What do we call <P = any> on ReactElement

Viewed 30

I have a question:

interface ReactElement<P = any, T extends string | 
    JSXElementConstructor<any> = string | JSXElementConstructor<any>> {
        type: T;
        props: P;
        key: Key | null;
    }

What does it mean: " P = any". I know that this is generic of Typescript, but I don't understand why having "=" in here. Thank you so much

1 Answers

<P = any> means that type any is a default type for P when P is not provided explicitly.

Short example:

interface R <P = any,T = any> {
        type: T;
        props: P;
    }


const a:R<number, number> = {type:22, props:333} //only numbers for type and props
const b:R = {type:null, props:'any'} //any type for type and props
Related