diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61acab1ed14..0eaffe07c02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8165,7 +8165,7 @@ namespace ts { // The expression is processed as an identifier expression (section 4.3) // or property access expression(section 4.10), // the widened type(section 3.9) of which becomes the result. - links.resolvedType = getWidenedType(checkExpression(node.exprName)); + links.resolvedType = getRegularTypeOfLiteralType(getWidenedType(checkExpression(node.exprName))); } return links.resolvedType; } diff --git a/tests/baselines/reference/typeofStripsFreshness.js b/tests/baselines/reference/typeofStripsFreshness.js new file mode 100644 index 00000000000..827021be944 --- /dev/null +++ b/tests/baselines/reference/typeofStripsFreshness.js @@ -0,0 +1,27 @@ +//// [typeofStripsFreshness.ts] +interface Collection { + elems: T[]; +} +interface CollectionStatic { + new (): Collection; +} +declare const Collection: CollectionStatic; + +const ALL = "all"; +type All = typeof ALL; + +const result: Collection = new Collection(); + +const ANOTHER = "another"; +type Another = typeof ANOTHER; + +type Both = Another | All; + +const result2: Collection = new Collection(); + + +//// [typeofStripsFreshness.js] +var ALL = "all"; +var result = new Collection(); +var ANOTHER = "another"; +var result2 = new Collection(); diff --git a/tests/baselines/reference/typeofStripsFreshness.symbols b/tests/baselines/reference/typeofStripsFreshness.symbols new file mode 100644 index 00000000000..2d3a2e67ad3 --- /dev/null +++ b/tests/baselines/reference/typeofStripsFreshness.symbols @@ -0,0 +1,52 @@ +=== tests/cases/compiler/typeofStripsFreshness.ts === +interface Collection { +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) +>T : Symbol(T, Decl(typeofStripsFreshness.ts, 0, 21)) + + elems: T[]; +>elems : Symbol(Collection.elems, Decl(typeofStripsFreshness.ts, 0, 25)) +>T : Symbol(T, Decl(typeofStripsFreshness.ts, 0, 21)) +} +interface CollectionStatic { +>CollectionStatic : Symbol(CollectionStatic, Decl(typeofStripsFreshness.ts, 2, 1)) + + new (): Collection; +>T : Symbol(T, Decl(typeofStripsFreshness.ts, 4, 9)) +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) +>T : Symbol(T, Decl(typeofStripsFreshness.ts, 4, 9)) +} +declare const Collection: CollectionStatic; +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) +>CollectionStatic : Symbol(CollectionStatic, Decl(typeofStripsFreshness.ts, 2, 1)) + +const ALL = "all"; +>ALL : Symbol(ALL, Decl(typeofStripsFreshness.ts, 8, 5)) + +type All = typeof ALL; +>All : Symbol(All, Decl(typeofStripsFreshness.ts, 8, 18)) +>ALL : Symbol(ALL, Decl(typeofStripsFreshness.ts, 8, 5)) + +const result: Collection = new Collection(); +>result : Symbol(result, Decl(typeofStripsFreshness.ts, 11, 5)) +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) +>All : Symbol(All, Decl(typeofStripsFreshness.ts, 8, 18)) +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) + +const ANOTHER = "another"; +>ANOTHER : Symbol(ANOTHER, Decl(typeofStripsFreshness.ts, 13, 5)) + +type Another = typeof ANOTHER; +>Another : Symbol(Another, Decl(typeofStripsFreshness.ts, 13, 26)) +>ANOTHER : Symbol(ANOTHER, Decl(typeofStripsFreshness.ts, 13, 5)) + +type Both = Another | All; +>Both : Symbol(Both, Decl(typeofStripsFreshness.ts, 14, 30)) +>Another : Symbol(Another, Decl(typeofStripsFreshness.ts, 13, 26)) +>All : Symbol(All, Decl(typeofStripsFreshness.ts, 8, 18)) + +const result2: Collection = new Collection(); +>result2 : Symbol(result2, Decl(typeofStripsFreshness.ts, 18, 5)) +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) +>Both : Symbol(Both, Decl(typeofStripsFreshness.ts, 14, 30)) +>Collection : Symbol(Collection, Decl(typeofStripsFreshness.ts, 0, 0), Decl(typeofStripsFreshness.ts, 6, 13)) + diff --git a/tests/baselines/reference/typeofStripsFreshness.types b/tests/baselines/reference/typeofStripsFreshness.types new file mode 100644 index 00000000000..e99d91dcfd0 --- /dev/null +++ b/tests/baselines/reference/typeofStripsFreshness.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/typeofStripsFreshness.ts === +interface Collection { +>Collection : Collection +>T : T + + elems: T[]; +>elems : T[] +>T : T +} +interface CollectionStatic { +>CollectionStatic : CollectionStatic + + new (): Collection; +>T : T +>Collection : Collection +>T : T +} +declare const Collection: CollectionStatic; +>Collection : CollectionStatic +>CollectionStatic : CollectionStatic + +const ALL = "all"; +>ALL : "all" +>"all" : "all" + +type All = typeof ALL; +>All : "all" +>ALL : "all" + +const result: Collection = new Collection(); +>result : Collection<"all"> +>Collection : Collection +>All : "all" +>new Collection() : Collection<"all"> +>Collection : CollectionStatic + +const ANOTHER = "another"; +>ANOTHER : "another" +>"another" : "another" + +type Another = typeof ANOTHER; +>Another : "another" +>ANOTHER : "another" + +type Both = Another | All; +>Both : Both +>Another : "another" +>All : "all" + +const result2: Collection = new Collection(); +>result2 : Collection +>Collection : Collection +>Both : Both +>new Collection() : Collection +>Collection : CollectionStatic + diff --git a/tests/cases/compiler/typeofStripsFreshness.ts b/tests/cases/compiler/typeofStripsFreshness.ts new file mode 100644 index 00000000000..93ef939a224 --- /dev/null +++ b/tests/cases/compiler/typeofStripsFreshness.ts @@ -0,0 +1,19 @@ +interface Collection { + elems: T[]; +} +interface CollectionStatic { + new (): Collection; +} +declare const Collection: CollectionStatic; + +const ALL = "all"; +type All = typeof ALL; + +const result: Collection = new Collection(); + +const ANOTHER = "another"; +type Another = typeof ANOTHER; + +type Both = Another | All; + +const result2: Collection = new Collection();