Comments (18)
What would that look like as a flow annotation?
from babel-plugin-flow-react-proptypes.
That's what I'm asking. I'd love to be able to define my propTypes in Flow,
but this would be a huge limitation if you can't do it.
On Wed, 28 Sep 2016, 16:43 Frankie Bagnardi, [email protected]
wrote:
What would that look like as a flow annotation?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#48 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABy6lzdtFai7NJUb1T42WSAb_CYy7QGVks5quvu6gaJpZM4KJW57
.
from babel-plugin-flow-react-proptypes.
From the react docs
// Anything that can be rendered: numbers, strings, elements or an array
// (or fragment) containing these types.
optionalNode: React.PropTypes.node,
So the prop would be a pretty complicated union type annotation. If there's an easier way to write this that's valid in flow we can add special support.
The best thing for now is probably to mark it as any
, which means anything except undefined (or null, I think).
from babel-plugin-flow-react-proptypes.
any will do for now. Can you add that to the README and maybe someone will
come up with a better solution.
On Wed, 28 Sep 2016, 18:54 Frankie Bagnardi, [email protected]
wrote:
From the react docs
// Anything that can be rendered: numbers, strings, elements or an array // (or fragment) containing these types. optionalNode: React.PropTypes.node,
So the prop would be a pretty complicated union type annotation. If
there's an easier way to write this that's valid in flow we can add special
support.The best thing for now is probably to mark it as any, which means
anything except undefined (or null, I think).—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#48 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABy6l9EjP92IZ31DixLzRNh9Ty94G1TPks5quxo6gaJpZM4KJW57
.
from babel-plugin-flow-react-proptypes.
I'm not going to put it in the readme, but hopefully someone else asks about it in an issue, and comes with solutions 😄
from babel-plugin-flow-react-proptypes.
The simplest way is to use
children: any
or maybe
children: React$Element
from babel-plugin-flow-react-proptypes.
Thanks, @MoOx. Where does React$Element
come from? I see in #14 you use ReactElement
. I stole your code and dropped it into a common _types.js
file:
export type ReactComponentState = {
[key: string]: any
}
export type ReactElement = any
export type ReactNode = (
state: ReactComponentState,
setState: (state: ReactComponentState) => void
) => ReactElement
It might be worth it for this lib to export these. Even if it's just export type ReactNode = any
, at least we would have a placeholder we could use for now.
from babel-plugin-flow-react-proptypes.
It should more be React$Element.
This comes from React core (not sure from where, but it's used here https://github.com/facebook/react/blob/16ac141f44583bd59f95f5b420a66bfcef01865e/flow/environment.js#L20)
from babel-plugin-flow-react-proptypes.
Isn't that just for elements, being objects with properties {type, props, key, ref}
?
from babel-plugin-flow-react-proptypes.
Yeah so maybe...
children: number | string | React$Element<any> | Array<number | string | React$Element<any>>
But it will become complicated to handle...
from babel-plugin-flow-react-proptypes.
The thing is... you can already kinda do that. The only thing special you need to do is make a file types.js:
export type ReactNode =
number
| string
| {type: string | function, props: object, key?: any, ref?: string | function}
| Array
And then import that in your component
import type {ReactNode} from './types';
type FooProps = {
x: ReactNode
}
So us adding extra support for it doesn't really change anything. Unless we want to do a string match on GenericTypeAnnotation for 'ReactNode' or similar... which is gross and won't work well if you're actually using flow as a type checker.
from babel-plugin-flow-react-proptypes.
Actually that doesn't work currently, it seems to ignore the type annotation, likely because it's not an object.
from babel-plugin-flow-react-proptypes.
I don't have experience with flow or Babel internals, but that's what I was
thinking. You export ReactNode and transform to PrppTypes.Node.
On Fri, 30 Sep 2016, 00:06 Frankie Bagnardi, [email protected]
wrote:
Actually that doesn't work currently, it seems to ignore the type
annotation, likely because it's not an object.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#48 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABy6lzSKmjL3t3b_tGVgVhdmKbbrG4Ftks5qvLTvgaJpZM4KJW57
.
from babel-plugin-flow-react-proptypes.
Cool. I don't know when I'll have time to work on this. Feel free to send a PR if you have the time.
from babel-plugin-flow-react-proptypes.
This seems to work for me:
import type { Children } from 'react';
type Props = {
children: Children,
};
EDIT: Granted, under the hood the type definition that the react
module is exporting is just Children: any
so in practice it's not much different than using any
.
from babel-plugin-flow-react-proptypes.
I've been using { children?: React.Element<*> }
as a node
analog.
from babel-plugin-flow-react-proptypes.
I think this should be working these days - if you use a shared exported type, you will get what you need.
from babel-plugin-flow-react-proptypes.
@mhaas fixed this, so try the latest version and let us know if you have any issues.
from babel-plugin-flow-react-proptypes.
Related Issues (20)
- PropTypes are not added to class components with intersected type parameters HOT 2
- Import type - implementation guidelines? HOT 4
- Not working when module.name_mapper is used HOT 1
- transforming recompose context props. HOT 1
- Types imported with `import *` (import star) are treated as values, causing runtime error HOT 4
- Add support for $ReadOnlyArray HOT 2
- Error when union types HOT 1
- Perform escape analysis on imported types HOT 3
- Fails to check "Objects as maps"
- Identifier 'PropTypes' has already been declared HOT 2
- Example form README is not transpiled correctly HOT 2
- plugin errors when parsing "empty" types HOT 2
- Undefined variable in output when input file contains two classes using same prop types HOT 4
- Using built-in generics in a generic type fails
- Add support for recursive data types
- aria-{name} and data-{name} props do not work HOT 1
- Issue when using with rollup imports HOT 2
- Support `React.ElementConfig`
- support webpack5
- Suppression only works for the very first directive (which might not be user-controllable)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-flow-react-proptypes.