apollo-tooling
apollo-tooling copied to clipboard
apollo-env polyfill fromentries does not match Typescript ES2019
Hi!
Currently, Object.fromentries in the apollo-env polyfill is declared as:
fromEntries<K extends string, V>(map: [K, V][]): Record<K, V>;
While the Typescript official method is:
fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T };
Since apollo-env is declared globally, it will overwrite the official method. And the official typing is nicer to work with.
Would it be possible to align the typing with the official one and/or remove it since it is now part of >ES2019.
Thanks!
It's also incorrect.
See the following code:
type Key = 'foo' | 'bar';
const keys: Key[] = ['foo'];
const b = Object.fromEntries<Key, number>(
keys.map((key) => {
return [key, 1];
}),
);
console.log(b.bar);
The type of b.bar is number but it evaluates to undefined.
The same code behaves as expected with official typing.
Both examples use noUncheckedIndexedAccess compiler flag.