Skip to content

Strip literal freshness from type queries #25471

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

Merged
merged 2 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8106,7 +8106,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;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/baselines/reference/typeofStripsFreshness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [typeofStripsFreshness.ts]
interface Collection<T> {
elems: T[];
}
interface CollectionStatic {
new <T>(): Collection<T>;
}
declare const Collection: CollectionStatic;

const ALL = "all";
type All = typeof ALL;

const result: Collection<All> = new Collection();

const ANOTHER = "another";
type Another = typeof ANOTHER;

type Both = Another | All;

const result2: Collection<Both> = new Collection();


//// [typeofStripsFreshness.js]
var ALL = "all";
var result = new Collection();
var ANOTHER = "another";
var result2 = new Collection();
52 changes: 52 additions & 0 deletions tests/baselines/reference/typeofStripsFreshness.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/typeofStripsFreshness.ts ===
interface Collection<T> {
>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 <T>(): Collection<T>;
>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<All> = 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<Both> = 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))

56 changes: 56 additions & 0 deletions tests/baselines/reference/typeofStripsFreshness.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=== tests/cases/compiler/typeofStripsFreshness.ts ===
interface Collection<T> {
>Collection : Collection<T>
>T : T

elems: T[];
>elems : T[]
>T : T
}
interface CollectionStatic {
>CollectionStatic : CollectionStatic

new <T>(): Collection<T>;
>T : T
>Collection : Collection<T>
>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<All> = new Collection();
>result : Collection<"all">
>Collection : Collection<T>
>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<Both> = new Collection();
>result2 : Collection<Both>
>Collection : Collection<T>
>Both : Both
>new Collection() : Collection<Both>
>Collection : CollectionStatic

19 changes: 19 additions & 0 deletions tests/cases/compiler/typeofStripsFreshness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface Collection<T> {
elems: T[];
}
interface CollectionStatic {
new <T>(): Collection<T>;
}
declare const Collection: CollectionStatic;

const ALL = "all";
type All = typeof ALL;

const result: Collection<All> = new Collection();

const ANOTHER = "another";
type Another = typeof ANOTHER;

type Both = Another | All;

const result2: Collection<Both> = new Collection();