chore(types): intellisense for colors #22151
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
Tests for the changes have been added (for bug fixes / features)Docs have been reviewed and added / updated if needed (for bug fixes / features)npm run build
) was run locallyand any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
The
Color
type is currentlyPredefinedColors | string
withPredefinedColors
being a string literal of the available predefined color names. Howeverstring
is a super-type of any string literal and therefore this is reduced by TypeScript to just thestring
type (which is correct behavior). However it has the problem that no suggestions are made in Intellisense.Issue Number: N/A
What is the new behavior?
See https://stackoverflow.com/a/61048124/2897426. There's a work-around that allows to have the correct type and also provide Intellisense for the string literal.
Does this introduce a breaking change?
Other information
One problem: any readme of a component that uses a prop with type
Color
would have this change:string & {}
as a type is confusing.(I have not pushed those readme changes yet.)
Maybe there's a way to get the readme generator to pick up
Color
as a type name instead of expanding the type? Or maybe we can just make it replacestring & {}
withstring
? (I could probably make a PR for Stencil).