Skip to content

.tip

· one of the small things

exactOptionalPropertyTypes makes undefined explicit

Without it, { name?: string } accepts { name: undefined }, which a spread, Object.keys and JSON all treat differently from having no name. With it on, the property is either there holding a string, or it's absent.

{ "compilerOptions": { "exactOptionalPropertyTypes": true } }

You'll have to change a handful of x: cond ? value : undefined spots to use spreads, and every one of them was a place where the two meanings were getting mixed up.

typescript