export class MyComponent extends Component {
props: {
here: string;
}
constructor(props) {
// ^^^^^ parameter `props`. Missing annotation
}
}
Flow should be able to infer the type of props because I've already written it down. Type inference works as expected in the render() function when I access this.props.
@wereHamster Type inference works fine, but for optimization flow asks to annotate all arguments of exported functions or public methods of exported classes. Just move props definitions out of class and most of the time you may use class properties
type Props = {
here: string
}
export class MyComponent extends Component<Props> {
constructor(props: Props) {
}
}
This probably can be closed.
/cc @vkurchatkin
@TrySound I am still facing this issue
The signature is as follows:
type Props = { //... }
const factory = () => {
class SomeClass extends React.PureComponent<Props> {
constructor(props) { //... }
}
}
Flow version: "flow-parser": "^0.89.0". Anything that I am missing? Thanks in advance.
@nikhil-varma You still need to specify type in constructor like in my example above. This is downside of classes. If you want to specify type only once use function components.
@TrySound But this seems to come only for a few components that I have written.. Others work just fine and do not throw this error. If I may, what issue with classes cause this? I have seen it work as well so was just curios to know.
Show me other components
The other components are as simple as follows & are multiple such instances..
type Props = { //... }
class SomeClass extends React.Component<Props>{
constructor(props) { super(props); //.. }
}
export default SomeClass;
I am using the flow-for-vscode extension in VSCode. Any chance that is causing this while parsing?
If the component is exported types are required. Otherwise they can be omitted.
How does the typing system depend on whether a Class is exported or not? Inference will not depend on whether it's exported or not I presume..
Flow requires all inputs for exported classes/functions to be typed to optimise the work and allow to handle modules in parallel.
Most not exported things inside module can be inferred.
So can this be a transient issue? Because I still am trying to understand how it's working for a few components and not others.. Does it deep infer files automatically and then understand based on the export? Apologize if the question is very basic.. :D
It's not an issue. Annotated exports is a requirement. Probably some components you see are not exported but used in another export component. Or those modules do not have flow annotation or treated as untyped in flowconfig.
Most helpful comment
It's not an issue. Annotated exports is a requirement. Probably some components you see are not exported but used in another export component. Or those modules do not have flow annotation or treated as untyped in flowconfig.