Bruno Henrique
Bruno Henrique

Reputation: 323

How make a attribute in interface required only when other attribute is true?

How make a relative required (only make required when other attribute is true)?

Example:

interface ITesteProps {
  required: boolean
  content{!required && '?'}: string
}

I know it's not a valid code. How make the content required only when the required === true? Is it possible?

Upvotes: 1

Views: 155

Answers (1)

user8082655
user8082655

Reputation:

you can do it like that:

type ITesteProps = { requred: true; content: string; } | {required: false; }

Upvotes: 3

Related Questions