refactor(compiler-cli): remove undesirable cast in the type translator (#38775)
The cast to `ts.Identifier` was a hack that "just happened to work". The new approach is more robust and doesn't have to undermine the type checker. PR Close #38775
This commit is contained in:
parent
6ae3b68acf
commit
856e74ac98
@ -742,9 +742,12 @@ export class TypeTranslatorVisitor implements ExpressionVisitor, TypeVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
visitTypeofExpr(ast: TypeofExpr, context: Context): ts.TypeQueryNode {
|
visitTypeofExpr(ast: TypeofExpr, context: Context): ts.TypeQueryNode {
|
||||||
let expr = translateExpression(
|
const typeNode = this.translateExpression(ast.expr, context);
|
||||||
ast.expr, this.imports, NOOP_DEFAULT_IMPORT_RECORDER, ts.ScriptTarget.ES2015);
|
if (!ts.isTypeReferenceNode(typeNode)) {
|
||||||
return ts.createTypeQueryNode(expr as ts.Identifier);
|
throw new Error(`The target of a typeof expression must be a type reference, but it was
|
||||||
|
${ts.SyntaxKind[typeNode.kind]}`);
|
||||||
|
}
|
||||||
|
return ts.createTypeQueryNode(typeNode.typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private translateType(type: Type, context: Context): ts.TypeNode {
|
private translateType(type: Type, context: Context): ts.TypeNode {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user