繁体   English   中英

是否可以在接口 Props 中添加任何值以在 React Typescript 中进行初始化?

[英]its possible to add any value in interface Props for initialization in React Typescript?

我需要一些帮助,我只是在学习打字稿,我想限制我的 finco 的价值,但我不能按我的方式做,这可能吗? 像这样

interface Props {
  finco?: string = 'TAF' | 'ACC'
}
interface Props {
  finco?: 'TAF' | 'ACC'
}

如果你只是把'TAF' | 'ACC' 'TAF' | 'ACC'作为类型,Typescript 将只接受这两个值之一作为finco字段的值。
(好吧,也是undefined

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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