Skip to content

The props type in the setup function may need to be more precise. #735

Closed
@nooooooom

Description

@nooooooom

We know that Vue will assign undefined to props that do not have a default value, but it still exists in propsOptions in the form of key value, and for TypeScript, optional parameters and parameters are of other types or undefined are two different definitions , It caused me to use toRefs for props in the setup function to make the parameters in the props become Ref | undefined, and I had to make assertions on the parameters, but it actually exists.

type Props = {
  a?: number
  b: number | undefined
}

type ToRefsProps = ToRefs<Props>

They are like Props.a and Props.b,In Vue, my parameters exist in the type of Props.b, but in the setup I get the type like Props.a.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions