typescript-generator icon indicating copy to clipboard operation
typescript-generator copied to clipboard

Feature Request: Add Support for Generating TypeScript Method Signatures from Java Class Methods

Open Mcayear opened this issue 5 months ago • 0 comments

Description:

Hi, and thanks for developing and maintaining typescript-generator! It's been an incredibly useful tool for generating TypeScript definition files from Java classes, especially for use cases involving JSON object mapping and static type checking in TypeScript.

However, I’ve noticed that currently, typescript-generator focuses primarily on generating TypeScript interfaces based on the fields (properties) of Java classes, but it doesn't generate TypeScript method signatures for the methods defined in these Java classes.

For example, given the following Java class:

public class Person {
    public String name;
    public int age;

    public String greet() {
        return "Hello, " + name;
    }
}

The output TypeScript interface would be:

interface Person {
    name: string;
    age: number;
}

Requested Feature:

I would like to request that typescript-generator be extended to also generate method signatures in the TypeScript definition files. Using the example above, the desired output would include the method signature as follows:

interface Person {
    name: string;
    age: number;

    greet(): string;
}

Why This Feature is Important:

  • Completeness: Many Java classes contain methods that perform important operations, and these methods are often integral to the class's functionality. Including method signatures in the generated TypeScript interfaces would provide a more complete representation of the Java class, reducing the need to manually extend the generated .d.ts files.

  • Consistency with Class Usage: In many TypeScript projects, it’s common to need both the data structure (fields) and the functionality (methods) provided by a Java class. Including methods would allow developers to fully type-check their TypeScript code that interacts with these Java classes.

Thank you for considering this request! This feature would greatly improve the usability of typescript-generator for projects that rely on Java methods in addition to fields.

Looking forward to your feedback and insights!

Mcayear avatar Sep 16 '24 11:09 Mcayear