[英]its possible to add any value in interface Props for initialization in React Typescript?
I need some help, I'm just learning typescript, I want to limit my finco's value, but I can't do it my way, Is this possible?我需要一些帮助,我只是在学习打字稿,我想限制我的 finco 的价值,但我不能按我的方式做,这可能吗? like this像这样
interface Props {
finco?: string = 'TAF' | 'ACC'
}
interface Props {
finco?: 'TAF' | 'ACC'
}
If you just put 'TAF' | 'ACC'
如果你只是把'TAF' | 'ACC'
'TAF' | 'ACC'
as the type, Typescript will only accept one of those two values as value of a the finco
field. 'TAF' | 'ACC'
作为类型,Typescript 将只接受这两个值之一作为finco
字段的值。
(well, and also undefined
) (好吧,也是undefined
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.