@@ -9142,8 +9142,12 @@ namespace ts {
91429142 }
91439143
91449144 function isTypeRelatedTo(source: Type, target: Type, relation: Map<RelationComparisonResult>) {
9145- source = getRegularTypeOfLiteralType(source);
9146- target = getRegularTypeOfLiteralType(target);
9145+ if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
9146+ source = (<LiteralType>source).regularType;
9147+ }
9148+ if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
9149+ target = (<LiteralType>target).regularType;
9150+ }
91479151 if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) {
91489152 return true;
91499153 }
@@ -9274,8 +9278,12 @@ namespace ts {
92749278 * * Ternary.False if they are not related.
92759279 */
92769280 function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
9277- source = getRegularTypeOfLiteralType(source);
9278- target = getRegularTypeOfLiteralType(target);
9281+ if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
9282+ source = (<LiteralType>source).regularType;
9283+ }
9284+ if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
9285+ target = (<LiteralType>target).regularType;
9286+ }
92799287 // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
92809288 if (source === target) return Ternary.True;
92819289
@@ -17205,36 +17213,6 @@ namespace ts {
1720517213 return globalESSymbol === resolveName(left, "Symbol" as __String, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
1720617214 }
1720717215
17208- function isCommonJsRequire(node: Node) {
17209- if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
17210- return false;
17211- }
17212-
17213- // Make sure require is not a local function
17214- if (!isIdentifier(node.expression)) throw Debug.fail();
17215- const resolvedRequire = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true);
17216- if (!resolvedRequire) {
17217- // project does not contain symbol named 'require' - assume commonjs require
17218- return true;
17219- }
17220- // project includes symbol named 'require' - make sure that it it ambient and local non-alias
17221- if (resolvedRequire.flags & SymbolFlags.Alias) {
17222- return false;
17223- }
17224-
17225- const targetDeclarationKind = resolvedRequire.flags & SymbolFlags.Function
17226- ? SyntaxKind.FunctionDeclaration
17227- : resolvedRequire.flags & SymbolFlags.Variable
17228- ? SyntaxKind.VariableDeclaration
17229- : SyntaxKind.Unknown;
17230- if (targetDeclarationKind !== SyntaxKind.Unknown) {
17231- const decl = getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
17232- // function/variable declaration should be ambient
17233- return isInAmbientContext(decl);
17234- }
17235- return false;
17236- }
17237-
1723817216 function checkImportCallExpression(node: ImportCall): Type {
1723917217 // Check grammar of dynamic import
1724017218 checkGrammarArguments(node.arguments) || checkGrammarImportCallExpression(node);
@@ -17287,6 +17265,36 @@ namespace ts {
1728717265 return type;
1728817266 }
1728917267
17268+ function isCommonJsRequire(node: Node) {
17269+ if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
17270+ return false;
17271+ }
17272+
17273+ // Make sure require is not a local function
17274+ if (!isIdentifier(node.expression)) throw Debug.fail();
17275+ const resolvedRequire = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true);
17276+ if (!resolvedRequire) {
17277+ // project does not contain symbol named 'require' - assume commonjs require
17278+ return true;
17279+ }
17280+ // project includes symbol named 'require' - make sure that it it ambient and local non-alias
17281+ if (resolvedRequire.flags & SymbolFlags.Alias) {
17282+ return false;
17283+ }
17284+
17285+ const targetDeclarationKind = resolvedRequire.flags & SymbolFlags.Function
17286+ ? SyntaxKind.FunctionDeclaration
17287+ : resolvedRequire.flags & SymbolFlags.Variable
17288+ ? SyntaxKind.VariableDeclaration
17289+ : SyntaxKind.Unknown;
17290+ if (targetDeclarationKind !== SyntaxKind.Unknown) {
17291+ const decl = getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
17292+ // function/variable declaration should be ambient
17293+ return isInAmbientContext(decl);
17294+ }
17295+ return false;
17296+ }
17297+
1729017298 function checkTaggedTemplateExpression(node: TaggedTemplateExpression): Type {
1729117299 if (languageVersion < ScriptTarget.ES2015) {
1729217300 checkExternalEmitHelpers(node, ExternalEmitHelpers.MakeTemplateObject);
@@ -24384,11 +24392,9 @@ namespace ts {
2438424392 function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
2438524393 // Get type of the symbol if this is the valid symbol otherwise get type at location
2438624394 const symbol = getSymbolOfNode(declaration);
24387- let type: Type = unknownType;
24388- if (symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))) {
24389- type = getTypeOfSymbol(symbol);
24390- type = getWidenedLiteralType(type);
24391- }
24395+ let type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
24396+ ? getWidenedLiteralType(getTypeOfSymbol(symbol))
24397+ : unknownType;
2439224398 if (flags & TypeFormatFlags.AddUndefined) {
2439324399 type = getNullableType(type, TypeFlags.Undefined);
2439424400 }
0 commit comments