What is the TypeScript return type of a React stateless component?

前端 未结 5 414
情深已故
情深已故 2021-01-07 16:17

What would the return type be here?

const Foo
  : () => // ???
  = () => (
    
Foobar
)
5条回答
  •  有刺的猬
    2021-01-07 17:02

    See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts

    Each JSX element is just syntactic sugar for calling React.createElement(component, props, ...children).

    function createElement

    , T extends Element>( type: string, props?: ClassAttributes & P, ...children: ReactNode[]): DOMElement;

    So it's DOMElement

提交回复
热议问题