TypeScript and React - children type?

前端 未结 14 1262
借酒劲吻你
借酒劲吻你 2020-12-12 18:56

I have a very simple functional component as follows:

import * as React from \'react\';

export interface AuxProps  { 
    children: React.ReactNode
 }


con         


        
14条回答
  •  春和景丽
    2020-12-12 19:06

    From the TypeScript site: https://github.com/Microsoft/TypeScript/issues/6471

    The recommended practice is to write the props type as {children?: any}

    That worked for me. The child node can be many different things, so explicit typing can miss cases.

    There's a longer discussion on the followup issue here: https://github.com/Microsoft/TypeScript/issues/13618, but the any approach still works.

提交回复
热议问题