Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/kotlin/ts2kt/typeScriptAstUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fun TypeNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType {

SyntaxKind.TypeReference -> (this.cast<TypeReferenceNode>()).toKotlinTypeUnion(typeMapper).singleType
SyntaxKind.ExpressionWithTypeArguments -> (this.cast<ExpressionWithTypeArguments>()).toKotlinType(typeMapper)
SyntaxKind.TypeQuery -> (this.cast<TypeQueryNode>()).toKotlinType(typeMapper)

SyntaxKind.Identifier -> KtType(KtQualifiedName((this.cast<Identifier>()).unescapedText))
SyntaxKind.TypeLiteral -> (this.cast<TypeLiteralNode>()).toKotlinType(typeMapper)
Expand Down Expand Up @@ -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<Node>().stringifyQualifiedName()?.asString())
}

private fun PropertyAccessExpression.toKtQualifiedName(): KtQualifiedName {
val identifier = identifierName.unescapedText

Expand Down
5 changes: 5 additions & 0 deletions testData/class/variables/varTypeOf.d.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package varTypeOf

external open class VarTypeOfClass {
open var myVar: dynamic /* typeof someOtherVar */ = definedExternally
}
3 changes: 3 additions & 0 deletions testData/class/variables/varTypeOf.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare class VarTypeOfClass {
myVar: typeof someOtherVar;
}