josephg / node-foundationdb

Modern Node.js FoundationDB bindings
Other
115 stars 17 forks source link

Add support for `exactOptionalPropertyTypes` TypeScript option #77

Closed keijokapp closed 2 months ago

keijokapp commented 3 months ago

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:

While I'm at it, would that be ok to do some maintenance tasks too? Like:

josephg commented 3 months ago

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?

keijokapp commented 3 months ago

Forgot about that. Done.