node-foundationdb icon indicating copy to clipboard operation
node-foundationdb copied to clipboard

Add support for `exactOptionalPropertyTypes` TypeScript option

Open keijokapp opened this issue 1 year ago • 2 comments

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 undefined to optional object field types where applicable (which is most of them).
  • Adds exactOptionalPropertyTypes: true to TypeScript configuration.
  • Removes boilerplate from tsconfig.json because 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

keijokapp avatar Apr 25 '24 10:04 keijokapp

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?

josephg avatar Apr 25 '24 10:04 josephg

Forgot about that. Done.

keijokapp avatar Apr 25 '24 11:04 keijokapp