At work, I was making a react component that can accept additional parameters, but I wanted to make the ide swear that if it didn’t pass a flag or some other prop
This led me to the next task
type ItemBase = {
title: string
//any other fields
}
type ItemFlagged = {
flag: true
additionField: string
}
type ItemNonFlagged = {
// empty object type
}
type ItemOptions = ItemFlagged | ItemNonFlagged
type Item = any //???
const a: Item = {
title: 'some'
}
const b: Item = {
title: 'some',
flag: true,
additionField: 'test'
}
// @ts-expect-error
const c: Item = {
title: 'c',
additionField: 'call'
}
Can you tell me if it is possible to make such a type, if so, then show how, and if not, what causes it
Thank you in advance