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
Component` [1] with less than 1 type argument #5869
Comments
Check out the Flow docs on working with React components: https://flow.org/en/docs/react/components/ Instead of using import React, { Component } from 'react';
type Props = {
className?: string,
disabled?: boolean
};
class Button extends Component<Props> {
static defaultProps = {
disabled: false
};
...
} You can get rid of the |
OK - so change a couple of 100 files in a project The example on the link doesn't cover how you deal with shapes / OneOfTypes ...... i.e
|
React.ChildrenArray allows a single or an array (nested to any level) of Nodes: myProp: React.ChildrenArray<React.Node> |
is there any way to suppress these warnings? just upgraded from |
I was late in replying to this, but you shouldn't have to manually fix this. The blog post for flow v0.53 mentions that you can use the Installationnpm install -g flow-upgrade Usage:flow-upgrade # Upgrade all files that have a // @flow annotation or flow-upgrade --all # Upgrade all files, even if they don't have a // @flow annotation |
Using propTypes is not the source of the errors by themselves, you're free to have both flow annotations and propTypes at the same time, however, flow errors if you don't annotate the props of your component. @saadq shows you how to keep your existing behaviour (i.e., avoid errors), but if you want, you can also use codemods to automatically generates the flow types from your propTypes. |
What is the reason for not just assuming EDIT: See https://medium.com/flow-type/even-better-support-for-react-in-flow-25b0a3485627 |
Yeah, it really should have a default... TypeScript sets props to an empty object by default: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L280 So if your component doesn't take any props, you don't need to use a generic when doing class MyComponent extends React.Component {
...
} |
Any is avoided wherever possible; it essentially just turns off the type checker and it easily propagates. Anything you get from an declare function f(): any;
var y = f() // y is any
var z = y.x // z is any Instead, |
|
If you think of the |
It actually seems like the |
well rip. Explicitly type your props, kids. |
Is there a way to deal with this if you're using comment types? Like, inline type annotations. |
bug:
I have a simple REACT 16 class that extends component.
It passes two properties
className
and 'disabled` (both are optional).The ONLY error in the code is from Flow - The error above..
Components source code included below ...
The text was updated successfully, but these errors were encountered: