momentum-mod / website

Momentum Mod's main website.
https://momentum-mod.org
MIT License
58 stars 59 forks source link

Enable exactOptionalPropertyTypes in TypeScript #855

Open tsa96 opened 11 months ago

tsa96 commented 11 months ago

This is a sensible flag that helps TS distinguish between fields that can be omitted and fields that can take a value of undefined. Enabling it stops you being able to set e.g. k?: string to undefined, and makes TypeScript's type inference when using index signatures a lot stronger - see https://github.com/microsoft/TypeScript/pull/43947

For us, it allows us to make nested interfaces containing optional values using extends JsonObject from type-fest, currently it just spews out errors about not being able to assign to some (e.g. string) index type, see https://github.com/sindresorhus/type-fest/issues/471#issuecomment-1284987356 for details.

TypeScript unfortunately doesn't have it on by default or in strict mode, but I'd definitely like to support it. I would add it right now, but it requires --strictNullChecks. So, once we finish https://github.com/momentum-mod/website/issues/792, this is a freebie.

I have to do a bunch of ugly as unknown as MapZones casts at the moment because of it, leaving comments everywhere that I am referencing this issue number. Once we tackle this, search for every instance and remove.