Reputation: 6185
The function is as follows:
const getProp = <
TObj extends object,
TKey extends keyof TObj
>(props: TObj, key: TKey, def: TObj[TKey]): TObj[TKey] => {
if (props[key] == null) return def
return props[key]
}
When used as follows:
const fluid = getProp(props, 'fluid', true) // return type is boolean | undefined
The return type is boolean | undefined
although I'd expect and need it to be boolean
.
Upvotes: 0
Views: 23