-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types(defineComponent): props support in TypeScript #3798
types(defineComponent): props support in TypeScript #3798
Conversation
This comment has been minimized.
This comment has been minimized.
6aeef21
to
0386adf
Compare
@Zclhlmgqzc can you fix to test locally run |
0386adf
to
498fb0b
Compare
Which code is better? export type DefineComponent<
...
- Props = Readonly<ExtractPropTypes<PropsOrPropOptions>> &
+ Props = Readonly<ExtractPropTypes<PropsOrPropOptions extends undefined ? {} : PropsOrPropOptions>> &
...
> or export type ExtractPropTypes<O> = O extends object
? { [K in keyof O]?: unknown } & // This is needed to keep the relation between the option prop and the props, allowing to use ctrl+click to navigate to the prop options. see: #3656
{ [K in RequiredKeys<O>]: InferPropType<O[K]> } &
{ [K in OptionalKeys<O>]?: InferPropType<O[K]> }
+ : O extends undefined
+ ? {}
: { [K in string]: any } |
Can't you just not pass |
because
const Comp = defineComponent({ props: {} })
==> {
props: {}
}
// Comp.props === {}
const Comp = defineComponent({})
==> {
props: undefined
}
// Comp.props === undefined
// @ts-expect-error
Comp.props.a |
Thanks, maybe the second option might be better (but just a preference) |
Thanks for your review |
see #5416 |
fix #3796