Repository navigation
IsLiteral*: Fix behavior with unions - #1482
Merged
Merged
Conversation
som-sm
force-pushed
the
fix/rewrite-is-literal-types
branch
from
July 4, 2026 08:38
0d654a8 to
e62591b
Compare
som-sm
force-pushed
the
fix/rewrite-is-literal-types
branch
from
July 9, 2026 10:26
85c8893 to
5ab7073
Compare
som-sm
marked this pull request as ready for review
July 9, 2026 10:44
Owner
|
The new union behavior makes sense, but this regresses branded broad primitives: type Brand = {readonly __brand: unique symbol};
type A = IsNumericLiteral<number & Brand>;
//=> true, should be false
type B = IsLiteral<Opaque<number, 'NumberTag'>>;
//=> true, should be falseThe old implementation explicitly stripped branding before checking whether a primitive was broad or literal, so I think the fix is to keep teh new distributive union behavior but reuse that branded-primitive check for numeric/boolean/symbol. |
Collaborator
Author
Added a new internal type Brand = {readonly __brand: unique symbol};
type A = UnwrapBrand<string & Brand>;
//=> string
type B = UnwrapBrand<Tagged<number, 'Tag'>>;
//=> number
type C = UnwrapBrand<Opaque<bigint, 'Tag'>>;
//=> bigint
type D = UnwrapBrand<PropertyKey & Brand>;
//=> PropertyKey
type E = UnwrapBrand<(1 | 200n | 'foo' | 'bar' | Uppercase<string>) & Brand>;
//=> 1 | 200n | 'foo' | 'bar' | Uppercase<string>Notice that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR primarily fixes the behavior of
IsLiteral*types when instantiated with a union of literals and non-literals. For example,IsNumericLiteral<1 | bigint>currently returnsfalse, instead it should returnboolean.This PR also makes a couple of other things:
Tagged/LiteralUniontypes.Also, the input to these literal types is currently unconstrained, but I think that should be constrained. For example,
IsStringLiteral<T extends string> = ...instead of justIsStringLiteral<T> = ....