Home > Net >  its possible to add any value in interface Props for initialization in React Typescript?
its possible to add any value in interface Props for initialization in React Typescript?

Time:11-12

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? like this

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

CodePudding user response:

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

If you just put 'TAF' | 'ACC' as the type, Typescript will only accept one of those two values as value of a the finco field.
(well, and also undefined)

  • Related