hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Overloaded methods are silently excluded from the generated typescript

Open Artur- opened this issue 3 years ago • 4 comments

Description of the bug

If you add

    public Integer myMethod() {
        return 1;
    }

    public String myMethod(String param) {
        return param;
    }

to an endpoint class, the resulting typescript contains

function _myMethod(
 param: string | undefined
): Promise<string | undefined>
{
 return client.call('MyEndpoint', 'myMethod', {param});
}

The first method returning an Integer has disappeared without a trace.

The preferred solution would be that overloaded methods work. If not possible, another solution would be to throw an error to let the user understand what is wrong.

Versions:

- Vaadin / Hilla version: 1.1.0-alpha4
- Node version: 18
- Java version: 17

Artur- avatar Apr 30 '22 09:04 Artur-

Implementation note: turns out, TypeScript supports overloaded definitions for as long as there is a separate implementation matching all definitions, for example:

class MyEndpoint {
    static async myMethod(): Promise<number>;

    static async myMethod(foo: string): Promise<string>;

    static async myMethod(...args: any[]): Promise<any> {
      // return client.call(...);
    }
}

platosha avatar May 03 '22 11:05 platosha