3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -16712,7 +16712,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16712
16712
}
16713
16713
// `var MyEnum: enum = { FirstValue: 1, SecondValue: 2 }` should resolve to a union of the enum values.
16714
16714
if (node.parent && isEnumLiteralDeclaration(node.parent)) {
16715
- return links.resolvedType = checkExpressionCached(( node.parent as VariableDeclaration) .initializer as Expression );
16715
+ return links.resolvedType = checkExpressionCached(node.parent.initializer);
16716
16716
}
16717
16717
let symbol: Symbol | undefined;
16718
16718
let type: Type | undefined;
Original file line number Diff line number Diff line change @@ -1883,6 +1883,15 @@ export interface VariableDeclaration extends NamedDeclaration, JSDocContainer {
1883
1883
readonly initializer ?: Expression ; // Optional initializer
1884
1884
}
1885
1885
1886
+ export interface EnumLiteralDeclaration extends VariableDeclaration {
1887
+ readonly kind : SyntaxKind . VariableDeclaration ;
1888
+ readonly parent : VariableDeclarationList ;
1889
+ readonly name : BindingName ;
1890
+ readonly exclamationToken : undefined ;
1891
+ readonly type : TypeReferenceNode ;
1892
+ readonly initializer : EnumLiteralExpression ;
1893
+ }
1894
+
1886
1895
/** @internal */
1887
1896
export type InitializedVariableDeclaration = VariableDeclaration & { readonly initializer : Expression ; } ;
1888
1897
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ import {
56
56
EntityName ,
57
57
entityNameToString ,
58
58
EnumDeclaration ,
59
+ EnumLiteralDeclaration ,
59
60
every ,
60
61
ExportAssignment ,
61
62
ExportDeclaration ,
@@ -1431,7 +1432,7 @@ export function isEnumTypeReference(node: Node): boolean {
1431
1432
return isTypeReferenceNode ( node ) && isIdentifier ( node . typeName ) &&
1432
1433
node . typeName . escapedText === "enum" && ! node . typeArguments ;
1433
1434
}
1434
- export function isEnumLiteralDeclaration ( node : Node ) : boolean {
1435
+ export function isEnumLiteralDeclaration ( node : Node ) : node is EnumLiteralDeclaration {
1435
1436
return isVariableDeclaration ( node ) && hasType ( node ) && isEnumTypeReference ( node . type ! ) && hasInitializer ( node ) && isEnumLiteralExpression ( node . initializer ! ) ;
1436
1437
}
1437
1438
0 commit comments