-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Widening and non-widening computed enum types #52542
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
Changes from all commits
cd7f039
340dae5
a84ac81
93e72f6
1b79c08
1129144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6028,7 +6028,8 @@ export const enum TypeFlags { | |||||||
/** @internal */ | ||||||||
Nullable = Undefined | Null, | ||||||||
Literal = StringLiteral | NumberLiteral | BigIntLiteral | BooleanLiteral, | ||||||||
Unit = Literal | UniqueESSymbol | Nullable, | ||||||||
Unit = Enum | Literal | UniqueESSymbol | Nullable, | ||||||||
Freshable = Enum | Literal, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intended for this to be public. |
||||||||
StringOrNumberLiteral = StringLiteral | NumberLiteral, | ||||||||
/** @internal */ | ||||||||
StringOrNumberLiteralOrUnique = StringLiteral | NumberLiteral | UniqueESSymbol, | ||||||||
|
@@ -6122,22 +6123,20 @@ export interface NullableType extends IntrinsicType { | |||||||
objectFlags: ObjectFlags; | ||||||||
} | ||||||||
|
||||||||
/** @internal */ | ||||||||
export interface FreshableIntrinsicType extends IntrinsicType { | ||||||||
freshType: IntrinsicType; // Fresh version of type | ||||||||
regularType: IntrinsicType; // Regular version of type | ||||||||
export interface FreshableType extends Type { | ||||||||
freshType: FreshableType; // Fresh version of type | ||||||||
regularType: FreshableType; // Regular version of type | ||||||||
Comment on lines
-6125
to
+6128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this intended to be public API now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||||||||
} | ||||||||
|
||||||||
/** @internal */ | ||||||||
export type FreshableType = LiteralType | FreshableIntrinsicType; | ||||||||
export interface FreshableIntrinsicType extends FreshableType, IntrinsicType { | ||||||||
} | ||||||||
|
||||||||
// String literal types (TypeFlags.StringLiteral) | ||||||||
// Numeric literal types (TypeFlags.NumberLiteral) | ||||||||
// BigInt literal types (TypeFlags.BigIntLiteral) | ||||||||
export interface LiteralType extends Type { | ||||||||
export interface LiteralType extends FreshableType { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could technically still keep export interface LiteralType extends FreshableType {}
export interface LiteralType {
freshType: LiteralType;
regularType: LiteralType; |
||||||||
value: string | number | PseudoBigInt; // Value of literal | ||||||||
freshType: LiteralType; // Fresh version of type | ||||||||
regularType: LiteralType; // Regular version of type | ||||||||
} | ||||||||
|
||||||||
// Unique symbol types (TypeFlags.UniqueESSymbol) | ||||||||
|
@@ -6159,7 +6158,7 @@ export interface BigIntLiteralType extends LiteralType { | |||||||
} | ||||||||
|
||||||||
// Enum types (TypeFlags.Enum) | ||||||||
export interface EnumType extends Type { | ||||||||
export interface EnumType extends FreshableType { | ||||||||
} | ||||||||
|
||||||||
// Types included in TypeFlags.ObjectFlagsType have an objectFlags property. Some ObjectFlags | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ declare enum E3 { | |
>E3 : E3 | ||
|
||
A | ||
>A : E3 | ||
>A : E3.A | ||
} | ||
declare module E3 { | ||
>E3 : typeof E3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
>E2 : E2 | ||
|
||
x = 'foo'.length | ||
>x : E2 | ||
>x : E2.x | ||
>'foo'.length : number | ||
>'foo' : "foo" | ||
>length : number | ||
|
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.
perhaps this "family" of functions could be renamed now? they all (
isFreshLiteralType
,getRegularTypeOfLiteralType
,getFreshTypeOfLiteralType
,getRegularTypeOfLiteralType
) mention "literal" type but now they will also handle enums and enums are not literal typesThere 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.
Yeah, but
isFreshFreshableType
andgetFreshTypeOfFreshableType
are pretty awful. 😮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.
Yeah, can't argue that 😅 OTOH, those names would be more correct - they sound a little bit weird at first but if we focus on their meaning, it makes sense.
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.
The fresh type of bel-air!
I suppose it could be argued that
Enum.A
is an “enum literal”, even if it’s not a literal in the grammatical sense. The compiler is treating it as one in a way by giving it its own nominal type (Enum
)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.
The main problem from my PoV, is that "literal" is already used in the codebase and it often doesn't include enums:
TypeScript/src/compiler/types.ts
Line 6042 in 3099385
I see now though that
EnumLiteral
also exist so maybe it isn't a big deal.