-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Extract<string, 'a'> != 'a' #47201
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
Comments
@MartinJohns I think it's analogous to the issue you mention it duplicates, but it does not require negated types. I've suggested an alternative implementation of Extract that works without changes to the language. |
I completely misread This is not a bug, but working as intended. You might want to rephrase it as a feature request. |
I think what you describe is not a bug, but the intended way that Extract works. type Narrow<Base,Target> = Target extends Base?Target:never
type A = Narrow<string,"a"> |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
Extract<string, 'a'>
isnever
, while it should be'a'
. A type likestring
could be seen as a virtual union of all literal string types. Therefore when extracting a literal from a more general type it is assignable to, the literal type should be returned.In other words, Extract should be implemented as:
🔎 Search Terms
Extract utility type
Extract literal from type
🕗 Version & Regression Information
This is present in v3.3.3 (oldest available in playground)
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Extract<string, 'a'>
isnever
🙂 Expected behavior
Extract<string, 'a'>
is'a'
The text was updated successfully, but these errors were encountered: