-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
React Component static properties #16967
Comments
To address this I think we need TypeScript to have the ability to have abstract static properties/methods in abstract classes: microsoft/TypeScript#14600 (comment) |
AFAICT, it should work to just copy the
|
Recommend react-typescript-helpers for defaultProps and propTypes. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes DefinitelyTyped#28515. Fixes DefinitelyTyped#16967.
- Copy properties from ComponentClass to the Component class. - Recommend the react-typescript-helpers package for checking the defaultProps and propTypes at a component definition. - As a fallback, have JSX.LibraryManagedAttributes check the defaultProps and propTypes every time a component is used. - Fix test failures in dependent packages. Fixes #28515. Fixes #16967.
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
React’s
Component
class supports static properties such asdisplayName
,defaultProps
,propTypes
, and others.When creating a component class, the common practice seems to be to extend the
Component
class type. However, theComponent
class type does not include these static properties. This means you don't get errors for these static properties:These static properties have instead been defined on a separate type, the
ComponentClass
interface. In order to get type checking for these static properties, one has to annotate the class using this interface:Is there any way we can consolidate these two types, so we get free type checking of static properties simply by extending
Component
?/cc React type definition authors: @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson
The text was updated successfully, but these errors were encountered: