13 ms·
Because `exactOptionalPropertyTypes` was only introduced relatively recently (https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/ https://devbl
by Benjamin_Dobell 4y ago
Because `exactOptionalPropertyTypes` was only introduced relatively recently (https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/ https://devblogs.microsoft.com/typescript/announcing-typescr...).
Without exact optional properties enabled, the type `{ age?: number }` will accept both `{}` and `{ age: undefined }`. With `exactOptionalPropertyTypes` enabled `{ age: undefined }` is illegal.
So `{ age?: number }` does mean the key is optional. If you want optional and supporting undefined then type you're after is `{ age?: undefined | number }`.
- wruza 4y agoThank you, this made it very clear!