mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Create typeof's string literal union type once
This changes the print order of string literal unions slightly. I think this is because 'string', 'symbol', etc are added to a union very early on in the creation of the checker.
This commit is contained in:
@@ -326,7 +326,6 @@ namespace ts {
|
||||
"object": TypeFacts.TypeofEQObject,
|
||||
"function": TypeFacts.TypeofEQFunction
|
||||
});
|
||||
|
||||
const typeofNEFacts = createMapFromTemplate({
|
||||
"string": TypeFacts.TypeofNEString,
|
||||
"number": TypeFacts.TypeofNENumber,
|
||||
@@ -336,7 +335,6 @@ namespace ts {
|
||||
"object": TypeFacts.TypeofNEObject,
|
||||
"function": TypeFacts.TypeofNEFunction
|
||||
});
|
||||
|
||||
const typeofTypesByName = createMapFromTemplate<Type>({
|
||||
"string": stringType,
|
||||
"number": numberType,
|
||||
@@ -344,6 +342,7 @@ namespace ts {
|
||||
"symbol": esSymbolType,
|
||||
"undefined": undefinedType
|
||||
});
|
||||
const typeofType = createTypeofType();
|
||||
|
||||
let jsxElementType: Type;
|
||||
let _jsxNamespace: string;
|
||||
@@ -1725,6 +1724,10 @@ namespace ts {
|
||||
return type;
|
||||
}
|
||||
|
||||
function createTypeofType() {
|
||||
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
|
||||
}
|
||||
|
||||
// A reserved member name starts with two underscores, but the third character cannot be an underscore
|
||||
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
|
||||
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
|
||||
@@ -14609,7 +14612,7 @@ namespace ts {
|
||||
|
||||
function checkTypeOfExpression(node: TypeOfExpression): Type {
|
||||
checkExpression(node.expression);
|
||||
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
|
||||
return typeofType;
|
||||
}
|
||||
|
||||
function checkVoidExpression(node: VoidExpression): Type {
|
||||
|
||||
Reference in New Issue
Block a user