Giter Club home page Giter Club logo

Comments (18)

brigand avatar brigand commented on September 22, 2024

What would that look like as a flow annotation?

from babel-plugin-flow-react-proptypes.

brettstack avatar brettstack commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

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.

brettstack avatar brettstack commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

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.

MoOx avatar MoOx commented on September 22, 2024

The simplest way is to use

children: any

or maybe

children: React$Element

from babel-plugin-flow-react-proptypes.

brettstack avatar brettstack commented on September 22, 2024

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.

MoOx avatar MoOx commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

Isn't that just for elements, being objects with properties {type, props, key, ref}?

from babel-plugin-flow-react-proptypes.

MoOx avatar MoOx commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

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.

brettstack avatar brettstack commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

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.

wesm87 avatar wesm87 commented on September 22, 2024

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.

limscoder avatar limscoder commented on September 22, 2024

I've been using { children?: React.Element<*> } as a node analog.

from babel-plugin-flow-react-proptypes.

mhaas avatar mhaas commented on September 22, 2024

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.

brigand avatar brigand commented on September 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.