'Because of `strictNullChecks` return type of function is `<type> | undefined` although it will never be undefined
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
