Return responds to 16 array elements in typescript

I want to use the new answer function 16 to return the elements of an array to mine render, but I get a typescript errorProperty 'type' is missing in type 'Element[]'

const Elements: StatelessComponent<{}> = () => ([
  <div key="a"></div>,
  <div key="b"></div>
]);

What am I missing? Using @ types / response 16.0.10 and typescript 2.5.3

+6
source share
2 answers

I checked the latest typifications, and they forgot to add new definitions to the stateless component interface. I raised a question, and this should be fixed soon.

, , , .

class Elements extends React.Component<{}> {

  render() {
    return [
       <div key="a"></div>,
       <div key="b"></div>
    ]

  }
}

React . - .ts , typescript .

declare module "react" {
  interface StatelessComponent<P = {}> {
    (props: P & { children?: ReactNode }, context?: any): ReactElement<any>[] | ReactElement<any> | null;
    propTypes?: ValidationMap<P>;
    contextTypes?: ValidationMap<any>;
    defaultProps?: Partial<P>;
    displayName?: string;
  }
}
+5

:

render() {
    return 
       <>
        <div key="a"></div>,
        <div key="b"></div>
       </>
}
0

All Articles