Type check JSX defaultProps as Partial<Props> #33951
Labels
Out of Scope
This idea sits outside of the TypeScript language design constraints
Suggestion
An idea for TypeScript
Suggestion
Currently, JSX
defaultProps
are not type-checked; any value can be passed to the properties of this object. One would think that they could fix it by defining the type ofdefaultProps
asPartial<Props>
but of course this breaks the default handling ofdefaultProps
where it marks all the props with keys indefaultProps
as optional.I suggest that instead, the compiler should check the value of
defaultProps
by treating it asPartial<Props>
when checking it, but still use the actual value of it when handling it.Use Cases
This is useful when writing any class-based react components. Currently I could set the default value of any prop to anything and no error will be shown, which is definitely a potential bug.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: