Description
This issue is to add support for parsing and transforming union types in typescript for the Dart JS Interop Generator
export type Color = 'red' | 'green' | 'blue';
export declare const stringOrNumber: string | number;
export declare const colorOrOther: Color | string;
Some union types can be reduced to base interop types such as JSString
for the typical "enum"-like union syntax ('red' | 'green' | 'blue'
), JSObject
, or JSAny
.
Custom Types
We are considering generating custom types containing an intersection of the properties contained in the union of the types (if any). We can make use of the typescript type checker API to find an intersection for these types, and add helpers for casting to the necessary union type, as well as checking if such type is one or the other.
We would also need to consider handling isA
checks if we are going on with custom types, as they do not exist on JS.
This option should be configurable as well, as users may choose to generate such custom type or not (i.e default to base intersection type)