Skip to content
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

Split literal strings from base types #57

Closed
johanneslumpe opened this issue Aug 16, 2018 · 2 comments
Closed

Split literal strings from base types #57

johanneslumpe opened this issue Aug 16, 2018 · 2 comments

Comments

@johanneslumpe
Copy link

johanneslumpe commented Aug 16, 2018

Properties like vertical-align allow literals but also the very wide string type. The issue with this is that TypeScript will widen the type to string, losing the ability to offer auto-completion hints for literal values and allowing any string value to pass type-checking. Would it be possible to define types which allow a very wide type like this:

type VerticalAlignPropertyBase<TLength> = Globals | TLength | "baseline" | "bottom" | "middle" | "sub" | "super" | "text-bottom" | "text-top" | "top";
type VerticalAlignProperty<TLength> = VerticalAlignPropertyBase<TLength> | string;

Auto-completion without split-out types
screen shot 2018-08-16 at 4 14 32 pm

Auto-completion with split-out types
screen shot 2018-08-16 at 4 14 40 pm

It's possible that I'm missing an obvious way to remove string from the union and be left only with the literal types and Globals/TLength, but so far I've been unlucky with my attempts.

@johanneslumpe
Copy link
Author

johanneslumpe commented Aug 16, 2018

Just realized that this is basically the same solution proposed in #8 (comment)

@frenic
Copy link
Owner

frenic commented Nov 5, 2019

Closing if favor of #74

@frenic frenic closed this as completed Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants