2 ms·
The second one raises an error: https://www.typescriptlang.org/play?#code/AQMwrgdgxgLglgewqBCBMAKAbgQwDZgCmAXMBGALYBGhATsAD7CQAmhIcEhLAlMAN4BfAFDBgwkKkw8gA htt
by goodoldneon 4y ago
The second one raises an error:
https://www.typescriptlang.org/play?#code/AQMwrgdgxgLglgewqBCBMAKAbgQwDZgCmAXMBGALYBGhATsAD7CQAmhIcEhLAlMAN4BfAFDBgwkKkw8gA https://www.typescriptlang.org/play?#code/AQMwrgdgxgLglgewqB...
This conflation of "optional" and "undefined-able" is more obvious in interfaces. This is why TypeScript added the `exactOptionalPropertyTypes` option:
https://www.typescriptlang.org/tsconfig#exactOptionalPropertyTypes https://www.typescriptlang.org/tsconfig#exactOptionalPropert...
Sometimes "is not defined" needs to be treated differently than "is set to undefined"