简体   繁体   English

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

[英]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.

相关问题 输入一个 React 组件,克隆其子组件以在 TypeScript 中添加额外的道具 - Typing a React component that clones its children to add extra props in TypeScript 在React Native中 - 是否可以在通过props收到的动画值上添加一个监听器? - In React Native - is it possible to add a listener on an Animated Value received through props? 在React中导出接口Props的目的是什么(Typescript ver) - What is the purpose of export interface Props in React (Typescript ver) 如何使用 Typescript 在 React 中循环两个接口 Props 的联合 - how to loop through the union of two interface Props in React with Typescript 在 React Typescript 中发送道具 - Sending props in React Typescript 为 onClick 属性添加类型,该属性位于 React TypeScript 中的 ...props 中 - Add type for onClick property which is in …props in React TypeScript 为 props 添加 Typescript 类型 - Add Typescript type to props 在React Typescript中是否可以将组件prop接口与另一个prop使用? - Is it possible in React Typescript to use a component prop interface with another prop? React Native,接受原生组件属性作为道具,并使用 TypeScript 接口自定义属性 - React Native, accept native component properties as props and have custom ones with a TypeScript interface 访问道具界面中的React类型 - Access React types in props interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM