UI5 / UI5/typescript

@ui5/ts-interface-generator: add generics to generated interface

Open
#376 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement ts-interface-generator
Dominant language
TypeScript
Stars
213
Forks
35
Avg merge
37m
Merged PRs (30d)
1

Description

Hi.

There is an issue when generating interfaces for generic classes. Example:

import ManagedObject from "sap/ui/base/ManagedObject";

/**
 * @namespace com.ts.test.tstest.util
 */
export default abstract class MyGenericClass<T> extends ManagedObject {
	static readonly metadata: object = {
		properties: {
			test: "string"
		}
	}
}

Generated interface:

import { PropertyBindingInfo } from "sap/ui/base/ManagedObject";
import { $ManagedObjectSettings } from "sap/ui/base/ManagedObject";

declare module "./MyGenericClass" {

    /**
     * Interface defining the settings object used in constructor calls
     */
    interface $MyGenericClassSettings extends $ManagedObjectSettings {
        test?: string | PropertyBindingInfo;
    }

    export default interface MyGenericClass {

        // property: test
        getTest(): string;
        setTest(test: string): this;
    }
}

As a result, error message is shown: All declarations of 'MyGenericClass' must have identical type parameters
Which, basically, means, that generated interface should be:

export default interface MyGenericClass<T> {

        // property: test
        getTest(): string;
        setTest(test: string): this;
    }

Would it be possible to add generics to the interface?
Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @ui5/ts-interface-generator and trace how it emits the generated interface for a generic class. Use the MyGenericClass example from the issue as the reproduction, then verify that the generated interface preserves the generic type parameter and no longer triggers the identical type-parameters error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.