Add support for `exactOptionalPropertyTypes` TypeScript option
TypeScript 4.4 introduced exactOptionalPropertyTypes compiler option. This fixed one of the major issues I had with TypeScript and, I think, should be the default in all new projects. It avoids unnecessary checks and type assertions/casts, improving type safety. But it also means that all optional object field types in the project, including those from third-party libraries, have to explicitly include undefined to preserve the old behavior.
This PR is mostly just convenience, so I could do
function foo(reverse?: boolean) {
return tn.getRange('', '\xff', { reverse });
}
instead of
function foo(reverse?: boolean) {
return tn.getRange('', '\xff', reverse != null ? { reverse } : {});
}
This PR:
- Adds
undefinedto optional object field types where applicable (which is most of them). - Adds
exactOptionalPropertyTypes: trueto TypeScript configuration. - Removes boilerplate from
tsconfig.jsonbecause it's weird to add options with the boilerplate in the way.
While I'm at it, would that be ok to do some maintenance tasks too? Like:
- Fix excess whitespaces at the end of lines. Most development environments should do this automatically, so excess whitespaces cause some pain.
- Fix trailing new lines to make Git and other tools happy. Again, most development environments should do this automatically.
- Update dependencies
- Possibly add a basic ESLint setup
Looks good. However, it looks like you've manually edited opts.d.ts - and that file should be autogenerated from one of the scripts. Any manual changes will be lost like this. Do you mind updating the generation script in scripts/gentsopts.ts while you're at it?
Forgot about that. Done.