frenic / csstype

Strict TypeScript and Flow types for style based on MDN data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TS 4.4: `exactOptionalPropertyTypes: true` support

nstepien opened this issue · comments

TypeScript 4.4's release is around the corner, and I'm testing it right now.
I'm hitting issues with csstype as properties are optional but do not explicitly allow undefined, for example

left?: Property.Left<TLength>;

should be

left?: Property.Left<TLength> | undefined;

https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-rc/

Support for this would be nice.

For reference: adazzle/react-data-grid#2566

My first thought was that maybe it would be expected to fail so you're notified when something can be removed. But I guess you're right. This would be annoying:

let myColor: string | undefined;

if (someCondition) {
  myColor: 'red';
}

const style: CSS.Properties = {
  color: myColor, // Guess this would cause a type error?
}

Yes that's right.

You can also end up with code that looks like this

const style: CSS.Properties = {
  color: records[key], // possibly undefined
  background: [].find(() => false) // possibly undefined
}

Waiting for TS 4.4 support too.

Released in 3.0.10