Tim Baas
Tim Baas

Reputation: 6185

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.

Upvotes: 0

Views: 23

Answers (0)

Related Questions