A generic Set keeps insertions consistent across the lifetime of the collection. Explicit type arguments are especially useful when the set starts empty.
Worked example
const entries: readonly (readonly [string, number])[] = [
["api", 2],
["web", 4],
];
console.log([...new Set<number>([2, 3, 2])]);Result
[ 2, 3 ]Implementation notes
Objects in a Set compare by identity. A Set of typed record objects will still accept two distinct objects with equivalent fields.
Try it yourself
Add an allowed value, then try a value of another type.
Open the TypeScript example →Editorial date December 3, 2025 · Published December 6, 2026