I am stuck in simple example, tried different tricks to narrow type but TS giving me errors. Consider following example:
interface IObject {
someField: string
}
interface ISomething {
inner: IObject | boolean
}
function returnValue(s: string, smth: ISomething): string {
if (s === 'inner')
return smth[s].someField
else
return ''
}
How would you tell TS that smth['inner'] is of type IObject, excluding boolean type so TS won't error: Property 'someField' does not exist on type 'boolean | IObject'. Property 'someField' does not exist on type 'false'.(2339)