@@ -2482,7 +2482,7 @@ namespace ts {
24822482 const immediate = resolveExternalModuleName(
24832483 node,
24842484 getExternalModuleRequireArgument(node) || getExternalModuleImportEqualsDeclarationExpression(node));
2485- const resolved = resolveExternalModuleSymbol(immediate);
2485+ const resolved = resolveExternalModuleSymbol(immediate);
24862486 markSymbolOfAliasDeclarationIfTypeOnly(node, immediate, resolved, /*overwriteEmpty*/ false);
24872487 return resolved;
24882488 }
@@ -2492,7 +2492,7 @@ namespace ts {
24922492 }
24932493
24942494 function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node: ImportEqualsDeclaration, resolved: Symbol | undefined) {
2495- if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false)) {
2495+ if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly ) {
24962496 const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node))!;
24972497 const isExport = typeOnlyDeclarationIsExport(typeOnlyDeclaration);
24982498 const message = isExport
@@ -6841,13 +6841,15 @@ namespace ts {
68416841 addResult(factory.createImportEqualsDeclaration(
68426842 /*decorators*/ undefined,
68436843 /*modifiers*/ undefined,
6844+ /*isTypeOnly*/ false,
68446845 uniqueName,
68456846 factory.createExternalModuleReference(factory.createStringLiteral(specifier))
68466847 ), ModifierFlags.None);
68476848 // import x = _x.z
68486849 addResult(factory.createImportEqualsDeclaration(
68496850 /*decorators*/ undefined,
68506851 /*modifiers*/ undefined,
6852+ /*isTypeOnly*/ false,
68516853 factory.createIdentifier(localName),
68526854 factory.createQualifiedName(uniqueName, initializer.name as Identifier),
68536855 ), modifierFlags);
@@ -6867,6 +6869,7 @@ namespace ts {
68676869 addResult(factory.createImportEqualsDeclaration(
68686870 /*decorators*/ undefined,
68696871 /*modifiers*/ undefined,
6872+ /*isTypeOnly*/ false,
68706873 factory.createIdentifier(localName),
68716874 isLocalImport
68726875 ? symbolToName(target, context, SymbolFlags.All, /*expectsIdentifier*/ false)
@@ -7024,6 +7027,7 @@ namespace ts {
70247027 addResult(factory.createImportEqualsDeclaration(
70257028 /*decorators*/ undefined,
70267029 /*modifiers*/ undefined,
7030+ /*isTypeOnly*/ false,
70277031 factory.createIdentifier(varName),
70287032 symbolToName(target, context, SymbolFlags.All, /*expectsIdentifier*/ false)
70297033 ), ModifierFlags.None);
@@ -12077,6 +12081,11 @@ namespace ts {
1207712081 else if (grandParent.kind === SyntaxKind.TemplateLiteralTypeSpan) {
1207812082 inferences = append(inferences, stringType);
1207912083 }
12084+ // When an 'infer T' declaration is in the constraint position of a mapped type, we infer a 'keyof any'
12085+ // constraint.
12086+ else if (grandParent.kind === SyntaxKind.TypeParameter && grandParent.parent.kind === SyntaxKind.MappedType) {
12087+ inferences = append(inferences, keyofConstraintType);
12088+ }
1208012089 }
1208112090 }
1208212091 }
@@ -15277,8 +15286,7 @@ namespace ts {
1527715286 }
1527815287 }
1527915288 // If the constraint type of the instantiation is the wildcard type, return the wildcard type.
15280- const result = <MappedType>instantiateAnonymousType(type, mapper);
15281- return getConstraintTypeFromMappedType(result) === wildcardType ? wildcardType : result;
15289+ return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
1528215290 }
1528315291
1528415292 function getModifiedReadonlyState(state: boolean, modifiers: MappedTypeModifiers) {
@@ -36459,9 +36467,12 @@ namespace ts {
3645936467 checkTypeNameIsReserved(node.name, Diagnostics.Import_name_cannot_be_0);
3646036468 }
3646136469 }
36470+ if (node.isTypeOnly) {
36471+ grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type);
36472+ }
3646236473 }
3646336474 else {
36464- if (moduleKind >= ModuleKind.ES2015 && !(node.flags & NodeFlags.Ambient)) {
36475+ if (moduleKind >= ModuleKind.ES2015 && !node.isTypeOnly && ! (node.flags & NodeFlags.Ambient)) {
3646536476 // Import equals declaration is deprecated in es6 or above
3646636477 grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
3646736478 }
@@ -36552,19 +36563,30 @@ namespace ts {
3655236563 });
3655336564 }
3655436565
36566+ function canConvertImportDeclarationToTypeOnly(statement: Statement) {
36567+ return isImportDeclaration(statement) &&
36568+ statement.importClause &&
36569+ !statement.importClause.isTypeOnly &&
36570+ importClauseContainsReferencedImport(statement.importClause) &&
36571+ !isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true) &&
36572+ !importClauseContainsConstEnumUsedAsValue(statement.importClause);
36573+ }
36574+
36575+ function canConvertImportEqualsDeclarationToTypeOnly(statement: Statement) {
36576+ return isImportEqualsDeclaration(statement) &&
36577+ isExternalModuleReference(statement.moduleReference) &&
36578+ !statement.isTypeOnly &&
36579+ getSymbolOfNode(statement).isReferenced &&
36580+ !isReferencedAliasDeclaration(statement, /*checkChildren*/ false) &&
36581+ !getSymbolLinks(getSymbolOfNode(statement)).constEnumReferenced;
36582+ }
36583+
3655536584 function checkImportsForTypeOnlyConversion(sourceFile: SourceFile) {
3655636585 for (const statement of sourceFile.statements) {
36557- if (
36558- isImportDeclaration(statement) &&
36559- statement.importClause &&
36560- !statement.importClause.isTypeOnly &&
36561- importClauseContainsReferencedImport(statement.importClause) &&
36562- !isReferencedAliasDeclaration(statement.importClause, /*checkChildren*/ true) &&
36563- !importClauseContainsConstEnumUsedAsValue(statement.importClause)
36564- ) {
36586+ if (canConvertImportDeclarationToTypeOnly(statement) || canConvertImportEqualsDeclarationToTypeOnly(statement)) {
3656536587 error(
3656636588 statement,
36567- Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_the_importsNotUsedAsValues_is_set_to_error );
36589+ Diagnostics.This_import_is_never_used_as_a_value_and_must_use_import_type_because_importsNotUsedAsValues_is_set_to_error );
3656836590 }
3656936591 }
3657036592 }
0 commit comments