Permit instantiation expressions in typeof import(...) (#52532)

This commit is contained in:
Anders Hejlsberg
2023-02-01 09:09:55 -08:00
committed by GitHub
parent 26eced32ed
commit d656487fca
8 changed files with 137 additions and 14 deletions
+5 -6
View File
@@ -17748,11 +17748,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getTypeFromImportTypeNode(node: ImportTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
if (node.isTypeOf && node.typeArguments) { // Only the non-typeof form can make use of type arguments
error(node, Diagnostics.Type_arguments_cannot_be_used_here);
links.resolvedSymbol = unknownSymbol;
return links.resolvedType = errorType;
}
if (!isLiteralImportTypeNode(node)) {
error(node.argument, Diagnostics.String_literal_expected);
links.resolvedSymbol = unknownSymbol;
@@ -17815,7 +17810,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const resolvedSymbol = resolveSymbol(symbol);
links.resolvedSymbol = resolvedSymbol;
if (meaning === SymbolFlags.Value) {
return getTypeOfSymbol(symbol); // intentionally doesn't use resolved symbol so type is cached as expected on the alias
return getInstantiationExpressionType(getTypeOfSymbol(symbol), node); // intentionally doesn't use resolved symbol so type is cached as expected on the alias
}
else {
const type = tryGetDeclaredTypeOfSymbol(resolvedSymbol); // call this first to ensure typeParameters is populated (if applicable)
@@ -34055,6 +34050,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const exprType = node.kind === SyntaxKind.ExpressionWithTypeArguments ? checkExpression(node.expression) :
isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) :
checkExpression(node.exprName);
return getInstantiationExpressionType(exprType, node);
}
function getInstantiationExpressionType(exprType: Type, node: NodeWithTypeArguments) {
const typeArguments = node.typeArguments;
if (exprType === silentNeverType || isErrorType(exprType) || !some(typeArguments)) {
return exprType;
-4
View File
@@ -1076,10 +1076,6 @@
"category": "Error",
"code": 1341
},
"Type arguments cannot be used here.": {
"category": "Error",
"code": 1342
},
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.": {
"category": "Error",
"code": 1343
+1 -1
View File
@@ -6409,7 +6409,7 @@ export interface AnonymousType extends ObjectType {
/** @internal */
export interface InstantiationExpressionType extends AnonymousType {
node: ExpressionWithTypeArguments | TypeQueryNode;
node: NodeWithTypeArguments;
}
/** @internal */