If you know how to fix the issue, make a pull request instead.
@types/xxxx package and had problems.Definitions by: in index.d.ts) so they can respond.If you do not mention the authors the issue will be ignored.
import React from 'react';
import PropTypes from 'prop-types';
class TestComponent extends React.Component {}
TestComponent.propTypes = {};
Error: Property 'propTypes' does not exist on type 'typeof TestComponent'.
But no error when using the static keyword.
import React from 'react';
import PropTypes from 'prop-types';
class TestComponent extends React.Component {
public static propTypes = {};
}
This is a standard TypeScript mechanism. With classes the expectation is that all static properties are initialized in the class definition. Adding it after the fact is only supported for functions.
and how would one add it after the fact with a function, because i get an error when doing it like this:
import Banner from './Banner';
...
const SubNav: React.FC<Props> = ({ className, items }) => { ... }
...
SubNav.Banner = Banner
Once you annotate a value with its type (like you did with const SubNav: React.FC<Props> you can't change its type afterwards, so you need to declare it all at once or redeclare it as another constant.
This error only serves to put people who are new to TS off gradually converting their code to TS. I'm having to litter my code with // @ts-ignore due to baffling errors like this when changing files from .js to .tsx and it catches no bugs.
In this case it catches no bugs. It catches a ton of bugs elsewhere. Type everything as “any” if you want this behavior. Also this is not an issue for DT as it is about the behavior of TS, not the types.
Please close.
I have a React class with Class.propTypes I change the module to .ts and all of a sudden it's buggy? What broke by just changing the file extension?
Most helpful comment
This is a standard TypeScript mechanism. With classes the expectation is that all static properties are initialized in the class definition. Adding it after the fact is only supported for functions.