mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Strip literal freshness from type queries (#25471)
* Strip literal freshness from type queries * Rename to fix typo
This commit is contained in:
parent
ea73ee7fd7
commit
547856a11d
@ -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;
|
||||
}
|
||||
|
||||
27
tests/baselines/reference/typeofStripsFreshness.js
Normal file
27
tests/baselines/reference/typeofStripsFreshness.js
Normal file
@ -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
tests/baselines/reference/typeofStripsFreshness.symbols
Normal file
52
tests/baselines/reference/typeofStripsFreshness.symbols
Normal file
@ -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
tests/baselines/reference/typeofStripsFreshness.types
Normal file
56
tests/baselines/reference/typeofStripsFreshness.types
Normal file
@ -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
tests/cases/compiler/typeofStripsFreshness.ts
Normal file
19
tests/cases/compiler/typeofStripsFreshness.ts
Normal file
@ -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();
|
||||
Loading…
x
Reference in New Issue
Block a user