-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Allow ExtractPropTypes to make props with default values optional #3122
Comments
+1 |
You really misunderstood the purpose of |
Yeah, it immediately clicked as soon as I checked CI outcome. Sorry for the hassle. Would it make sense to expose a prop utility to get typings from a parent’s scope perspective, like HcySunYang mentioned? |
+1 const todoItemProps = {
item: {
type: String,
default: '',
required: false
},
complete: {
type: Boolean,
default: false,
required: false
}
}
export type TodoItemProps = ExtractPropTypes<typeof todoItemProps>
const myDodoItemProps: TodoItemProps = {
item: 'd'
} As shown in the figure, when the required parameter of props is false, the declaration should be an optional attribute. But it is actually prompted that there is still a complete property that is not defined, so I suspect that there may be a problem with ExtractPropTypes? Is this an unresolved issue, or am I not using it correctly? |
Version
3.0.5
Reproduction link
https://codesandbox.io/s/stoic-hamilton-t8cft?file=/src/index.ts
Steps to reproduce
Access props via
setup()
block or useExtractPropTypes
utility to check props type inference (reproduction link has a naive example).What is expected?
Props with a
default
property configured shouldn’t be marked as required by TS.Edit: Seems like maybe I misunderstood the purpose of said utility.
ExtractPropTypes
is giving type safety toprops
argument, but not for objects that are safe to be bound to components with such properties.Maybe there should be another utility that yield proper types from the binding perspective (as in, marking props with
default
properties as optional).What is actually happening?
RequiredKeys<>
TS utility is marking props that havedefault
property as required (even if they are explicitly configured withrequired: false
).The text was updated successfully, but these errors were encountered: