Flow: React.StatelessFunctionalComponent<Props> type arguments errors

Created on 18 Aug 2017  路  2Comments  路  Source: facebook/flow

Using the new React.StatelessFunctionalComponent<Props> type, I tried to declare a component like this:

type FooProps = {| size?: 1 | 2 | 3 |};
const Foo: React.StatelessFunctionalComponent<FooProps> = props => /* component definition */

but this resulted in the following errors:

9: const Foo: React.StatelessFunctionalComponent<FooProps> = props =>
              ^ type application of StatelessFunctionalComponent. Too few type arguments. Expected at least 2
[LIB] static/v0.53.1/flowlib/react.js:204:   declare export type StatelessFunctionalComponent<P, C> =
                                                                                              ^ See type parameters of definition here
9: const Foo: React.StatelessFunctionalComponent<FooProps> = props =>
              ^ type application of polymorphic type: type `React$StatelessFunctionalComponent`. Too many type arguments. Expected at most 1
[LIB] static/v0.53.1/flowlib/react.js:124: declare type React$StatelessFunctionalComponent<Props> = {
                                                                                           ^ See type parameters of definition here

https://flow.org/try/#0PTAEAEDMBsHsHcBQiCWBbADrATgF1AFSgCGAzqAEoCmxAxvpNrGqAETY32sDcytsAO1L5aoALyVOuAHS0OxXFQCi0KmioDcvRLgCeGKqABisWAAUmGchIDeAH0ShQpFAC8qAfgBcoAIyg7UAAmANAAZkQ7AF9tfiF8E1gfajoZAGVcBSpVUlIjAFcBehRBYmgAYWYsAQ1cAB5Ei1grAD5xUAxLaxbHUFoAClYAExQAN1YAGlAbXqdhXVUfGacV0AALKhQAczXcH07m0mkXdwDA3wnZlfgUIdw1-a7jt0M7c6uo3qiASm0qAA8sHhQEMqJBiPloAlTLwgA

Is declaring components like this not supported, or am I missing something?

Most helpful comment

I think the bug is that StatelessFuntionalComponent is first defined with just one polymorphic type variable for Props but then exported with two type variables, including one for context type.

All 2 comments

I think the bug is that StatelessFuntionalComponent is first defined with just one polymorphic type variable for Props but then exported with two type variables, including one for context type.

I'm also slightly confused by the fact that Flow's example for stateless components doesn't use the StatelessFunctionalComponent type.

Was this page helpful?
0 / 5 - 0 ratings