facebook/idx

Add support for Map.get in .ts files

abobr opened this issue · 2 comments

abobr commented

Currently writing:

 idx(obj, _ => _.someMapProp.get(someKey).subValue)

in typescript file gives an error:
TS2533: Object is possibly 'null' or 'undefined'

abobr commented

Something like that:

type DeepRequiredMap<K, V> = {
  get(p: K): DeepRequired<V>
}
type DeepRequired<T> = T extends any[]
  ? DeepRequiredArray<T[number]>
  : T extends (...args: any[]) => any
    ? FunctionWithRequiredReturnType<T>
    : T extends Map<infer K, infer V>
      ? DeepRequiredMap<K, V>
      : T extends object ? DeepRequiredObject<T> : T;

Currently, idx does not support call expressions such as .get(...): https://github.com/facebookincubator/idx/blob/master/packages/babel-plugin-idx/src/babel-plugin-idx.js#L147

As a reminder, idx is intended to be used with babel-plugin-idx. In fact, the runtime implementation is strictly for illustrative purposes: https://github.com/facebookincubator/idx/blob/master/packages/idx/src/idx.js#L44