LexiFi / gen_js_api

Easy OCaml bindings for Javascript libraries
MIT License
177 stars 31 forks source link

Unions based on JS class name and typeof? #158

Open Lupus opened 3 years ago

Lupus commented 3 years ago

TypeScript very often has the following unions defined:

export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration;

export interface TypeOperatorNode extends TypeNode {
        readonly kind: SyntaxKind.TypeOperator;
        readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword;
        readonly type: TypeNode;
    }

getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;

Some of them can be discriminated by class constructor names, others can be discriminated by the type of value (string vs number for example). Currently gen_js_api does not seem to support this use cases. Would be great to have such feature.