From 075435ee62dfe934de840d60ee71dcfef7aea654 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 17:20:02 +0100 Subject: Support Box and Shared in typescript-types --- .../generators/typescript/TypescriptGenerator.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java index 3832f35..c26b73d 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/typescript/TypescriptGenerator.java @@ -1,5 +1,6 @@ package org.zwobble.hobgoblin.compiler.output.generators.typescript; +import org.zwobble.hobgoblin.compiler.builtins.NativeTypes; import org.zwobble.hobgoblin.compiler.output.lang.typescript.TypescriptWriter; import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.*; import org.zwobble.hobgoblin.compiler.types.*; @@ -41,7 +42,7 @@ public class TypescriptGenerator { } public TypescriptExpression generateTypeExpression(Type value) { - return switch (value) { + return switch (collapseType(value)) { case ConstructedType constructedType -> { yield new TypescriptConstructedType( generateTypeExpression(constructedType.constructor().genericType()), @@ -71,4 +72,19 @@ public class TypescriptGenerator { } }; } + + public Type collapseType(Type type) { + if (!(type instanceof ConstructedNativeType constructedNativeType)) { + return type; + } + + if ( + !constructedNativeType.constructor().equals(NativeTypes.SHARED) && + !constructedNativeType.constructor().equals(NativeTypes.BOX) + ) { + return type; + } + + return constructedNativeType.args().getFirst(); + } } -- cgit v1.2.3