Vertispan / jsinterop-ts-defs

Ingests jsinterop-annotated Java and generates TypeScript definitions
Apache License 2.0
7 stars 3 forks source link

Type unions don't work in arrays, only JsArray #66

Closed niloc132 closed 1 year ago

niloc132 commented 1 year ago
public void foo(MyUnionType[] param);

where MyUnionType maps to something like string | number. I would expect this to generate

foo(param:Array<string | number>);

but instead, I am seeing

foo(param:[])

Aside, from what I can tell, you can't actually make a nice way of saying (string | number)[], so the Array<...> syntax is the only way to generate ts output with an array of a union, at least without another @type decl. For this reason, I suspect we will want to change both java arrays and JsArray types to be handled as the same kind of array in ts.

Workaround, declare a JsArray instead:

public void foo(JsArray<MyUnionType> param);

This correctly generates:

foo(param:Array<string | number>);