I noticed I forgot to add a generic for a Set
in code I wrote a long time ago. It’s typed as Set<unknown>
. Surprisingly, this allows me to use all the Set
methods without errors. With arrays, if I type it as unknown[]
, it’ll throw errors. E.g.:
const set = new Set();
set.has(1);
const map = new Map();
map.has(1);
const arr = []; // Variable 'arr' implicitly has type 'any[]' in some locations where its type cannot be determined.
arr.includes(1); // Variable 'arr' implicitly has an 'any[]' type.
How can I make Set and Map also throw errors if their types are unknown?