frenic / csstype

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

FontWeight doesn't accept absolute values passed as strings #125

Closed villasv closed 2 years ago

villasv commented 3 years ago

I'm getting Type '"100"' is not assignable to type 'FontWeight | undefined'. when using a library that specifies a few CSS constants and declares it's types as possibly stringified numerals.

frenic commented 3 years ago

Union string (... | string) is needed to make this work today and is avoided whenever possible. To solve this we first need to implement a TS4.1 alternative and use number | `${number}` to make 100 and "100" work, but not e.g. "lihgter".

villasv commented 3 years ago

Any pointer for me to go about it? I think I have the time to contribute, but I couldn't figure out how to based on recent pull requests.

frenic commented 3 years ago

That would be helpful! This guy converts CSSType-"types" into understandable TypeScript types. The string template literal needs to be opt-in here somewhere so we can generate a d.ts with string template literals and one without later on.

frenic commented 2 years ago

Union string is now also applied wherever union number is applied. Released in 3.0.10. I need more time to solve this separately with template string for TS4.1+.