Default property value in React component using TypeScript

前端 未结 7 1010
温柔的废话
温柔的废话 2020-11-28 01:51

I can\'t figure out how to set default property values for my components using Typescript.

This is the source code:

class PageState
{
}

export class         


        
相关标签:
7条回答
  • 2020-11-28 02:18

    With Typescript 2.1+, use Partial < T > instead of making your interface properties optional.

    export interface Props {
        obj: Model,
        a: boolean
        b: boolean
    }
    
    public static defaultProps: Partial<Props> = {
        a: true
    };
    
    0 讨论(0)
提交回复
热议问题