mattpocock / ts-reset

A 'CSS reset' for TypeScript, improving types for common JavaScript API's
https://www.totaltypescript.com/ts-reset
MIT License
7.9k stars 124 forks source link

As of `0.6.0`, `new Map()` cannot satisfy existing generic constraints #206

Closed amitdahan closed 2 months ago

amitdahan commented 2 months ago

Related #41, and specifically - this bug was introduced in #53.


Previously (when new Map() returned a Map<any, any>) - this would have worked:

function expectsBooleanMap(map: Map<string, boolean>) {}
expectsBooleanMap(new Map());

But with 0.6.0 it no longer works!

error TS2345: Argument of type 'Map<unknown, unknown>' is not assignable to parameter of type 'Map<string, boolean>'.

This also reproduces with usages such as:

const map: Map<string, boolean> = new Map();
const map = new Map() satisfies Map<string, boolean>;
jaens commented 2 months ago

Can confirm, after upgrade most new Map()s return a type error now, before they were type inferred properly.

(needed to revert to previous version)