-
-
Notifications
You must be signed in to change notification settings - Fork 616
Add ExtractLiterals
and IsPrimitive
types
#1145
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
base: main
Are you sure you want to change the base?
Conversation
21a5190
to
331aa21
Compare
The name is incorrect. Should be something like And I think it should be strict by default. |
What about |
I agree that
Also, agree on this. |
Add `Extends` internal type Improve `IsLiteral` type
ExtractLiterals
and IsPrimitive
typeExtractLiterals
and IsPrimitive
types
07e76cd
to
fbab98c
Compare
fbab98c
to
96b1e17
Compare
Hey guys👋, any updates or reviews ? |
@benzaria Looks like the PR does so many things now. Anyways, here are my thoughts:
For now, maybe we can keep it simple and just add Also, just curious, do you have any use cases where treating infinite string types like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to keep the PR focused on a single thing, bundling too many changes together makes it harder to review and understand the overall impact.
But if it does it will be just and
Yes I want to introduce a type IsInfinitLiteral<T> =
T extends unknown
? And<
Not<IsLiteral<T>>,
Not<IsPrimitive<T>>
>
: never |
So After thinking |
Create a union by removing all Non-Literal primitive types from a union, while retaining literal types.
This utility helps you extract only the literal members from a "literal union" type
(e.g.,
'foo' | 'bar' | string
becomes'foo' | 'bar'
), saving you from defining separate types for literals and unions.It works with all primitive and tagged types, and supports two strictness modes:
Strict = true
): Removes any infinite signature type (e.g.,abc${string}
,123${number}
), keeping only genuine literals.Strict = false
): Removes only wide primitive types (e.g.,string
,number
).default: false