diff --git a/src/main/kotlin/ts2kt/typeScriptAstUtils.kt b/src/main/kotlin/ts2kt/typeScriptAstUtils.kt index e2af129..e8459ac 100644 --- a/src/main/kotlin/ts2kt/typeScriptAstUtils.kt +++ b/src/main/kotlin/ts2kt/typeScriptAstUtils.kt @@ -266,6 +266,7 @@ fun TypeNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType { SyntaxKind.TypeReference -> (this.cast()).toKotlinTypeUnion(typeMapper).singleType SyntaxKind.ExpressionWithTypeArguments -> (this.cast()).toKotlinType(typeMapper) + SyntaxKind.TypeQuery -> (this.cast()).toKotlinType(typeMapper) SyntaxKind.Identifier -> KtType(KtQualifiedName((this.cast()).unescapedText)) SyntaxKind.TypeLiteral -> (this.cast()).toKotlinType(typeMapper) @@ -320,6 +321,10 @@ fun ExpressionWithTypeArguments.toKotlinType(typeMapper: ObjectTypeToKotlinTypeM return KtType(name ?: KtQualifiedName("???"), typeArguments?.arr?.map { typeMapper.mapType(it) } ?: emptyList()) } +fun TypeQueryNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType { + return KtType(DYNAMIC, comment = "typeof " + this.exprName.unsafeCast().stringifyQualifiedName()?.asString()) +} + private fun PropertyAccessExpression.toKtQualifiedName(): KtQualifiedName { val identifier = identifierName.unescapedText diff --git a/testData/class/variables/varTypeOf.d.kt b/testData/class/variables/varTypeOf.d.kt new file mode 100644 index 0000000..35f5abf --- /dev/null +++ b/testData/class/variables/varTypeOf.d.kt @@ -0,0 +1,5 @@ +package varTypeOf + +external open class VarTypeOfClass { + open var myVar: dynamic /* typeof someOtherVar */ = definedExternally +} diff --git a/testData/class/variables/varTypeOf.d.ts b/testData/class/variables/varTypeOf.d.ts new file mode 100644 index 0000000..823c1f8 --- /dev/null +++ b/testData/class/variables/varTypeOf.d.ts @@ -0,0 +1,3 @@ +declare class VarTypeOfClass { + myVar: typeof someOtherVar; +}