frenic / csstype

Strict TypeScript and Flow types for style based on MDN data
MIT License
1.73k stars 72 forks source link

TS 4.4: `exactOptionalPropertyTypes: true` support #137

Closed nstepien closed 2 years ago

nstepien commented 3 years ago

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: https://github.com/adazzle/react-data-grid/pull/2566

frenic commented 3 years ago

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?
}
nstepien commented 3 years ago

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
}
nstepien commented 3 years ago

It's out! https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/

daniele-orlando commented 2 years ago

Waiting for TS 4.4 support too.

frenic commented 2 years ago

Released in 3.0.10