-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template literal types for strongly typed string values #131
Comments
I should have experimented a bit more, because I just bumped up against |
Template string literals will be used to some extent but we need to ensure the performance and be able to support TS < 4.1 with a separate definition file (without template string literals). |
After spending several hours on this myself, I've gotten it to work, but the types degrade quickly in cases of the newly proposed color functions, where you could pass the value of There is a TS proposal that is suggesting adding regex types for additional string validation, I think this body of work in CSSType is probably best left until that is [hopefully] added in, otherwise you can only be exact up to a certain point before needing to degrade your type specificity. |
Thank you for digging into this! I think even with regex validation of string value types will be hard to work with. Image the error message you will receive when doing a minor mistake, that the browser even in several cases will forgive. But we'll see when, and if, something like that will be implemented in TS. |
While I agree that strongly-typing
Would you accept a pull request? Do you have any further thoughts? |
Also, what's the rationale for not exporting the |
I'm working on a library that's essentially typescript functions that generate valid CSS. Having just discovered template literal types, I figured out that you can essentially have strongly typed CSS strings. I think this could help tighten up
csstype
's property types even further for things like CSS units, colors, functions, etc.Some examples:
With the above types, you restrict the types of strings that are allowed to be passed into other interpolated string types to form strongly typed CSS.
This means that the
Properties
interface could become more strict to be something like:Is this something that sounds useful for these type definitions? Is it something that's doable based on how the type definitions are even being generated?
The text was updated successfully, but these errors were encountered: