We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version:
1.7.5
Code
class Foo extends React.Component<any, any> { // ... some class definitions } Foo.defaultProps = { bar: 'baz' }
Expected behavior:
No error.
Actual behavior:
TS2339: Property 'defaultProps' does not exist on type 'typeof Foo'.
Hi, I'd like to create react class using typescript with ES6 classes, and encountered above error.
It would be awesome if I can set class property like above instead of class body. seems typescript does not supports it?
The text was updated successfully, but these errors were encountered:
The error is that by default there is no defaultProps static property on Foo. So you just have to tell the compiler that you want such a property.
defaultProps
Foo
class Foo extends React.Component<any, any> { static defaultProps: any; } Foo.defaultProps = { bar: 'baz' }
In general, if the props was of some type P instead of any, then it would be class Foo extends React.Component<P, ... and static defaultProps: P;
P
any
class Foo extends React.Component<P, ...
static defaultProps: P;
Sorry, something went wrong.
You can also use module merging for slightly less code:
class Foo { ... } namespace Foo { export const defaultProps = { ... } }
Thank you very much for kind answers! 👍
No branches or pull requests
TypeScript Version:
1.7.5
Code
Expected behavior:
No error.
Actual behavior:
TS2339: Property 'defaultProps' does not exist on type 'typeof Foo'.
Description
Hi, I'd like to create react class using typescript with ES6 classes, and encountered above error.
It would be awesome if I can set class property like above instead of class body. seems typescript does not supports it?
The text was updated successfully, but these errors were encountered: