简体   繁体   中英

Typescipt: intersection for setting default props in react

在此处输入图像描述

I want to use intersection so I dont have to explicitly write every type of my defaultProps but rather take it's type from my declared variable, is that possible? As you can see in my code example even thought myProp is set as nullable, it isn't accepting null value

An intersection combines existing types meaning all the types on both object are present. You cannot use the type of the declared variable to define testProps if its a union of multiple types, as when you set the default value you bind it to a particular type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM