💾 Archived View for envs.net › ~saurabh › dev › js-coercion-syndrome.gmi captured on 2023-03-20 at 18:40:41. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

JS Coercion Syndrome

type Mapish = { [k: string]: boolean };
type M = keyof Mapish;

Try to guess the type of M

type M = string | number

Surprised?

According to the Typescript documentation:

Note that in this example, M is string | number — this is because JavaScript object keys are always coerced to a string, so obj[0] is always the same as obj["0"].

See for yourself.

hashtag just-js-things