SAP / ui5-typescript

Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects
https://sap.github.io/ui5-typescript
Apache License 2.0
201 stars 28 forks source link

ts error when naming a class equal to its superclass #351

Closed Revest117 closed 2 years ago

Revest117 commented 2 years ago

File: example/control/ObjectPageLayout.ts

import SAPObjectPageLayout from "sap/uxap/ObjectPageLayout";
import SAPObjectPageLayoutRenderer from "sap/uxap/ObjectPageLayoutRenderer";

/**
 * @namespace example.control
 */

export default class ObjectPageLayout extends SAPObjectPageLayout {

    constructor(idOrSettings?: string | $ObjectPageLayoutSettings);
    constructor(id?: string, settings?: $ObjectPageLayoutSettings);
    constructor(id?: string, settings?: $ObjectPageLayoutSettings) {
        super(id, settings);
    }

    static readonly metadata = {
        "properties": {
            "example": {
                "type": "string"
            }
        }
    };

    renderer = SAPObjectPageLayoutRenderer;
}

The generated gen.d.ts File

import { $ObjectPageLayoutSettings } from "sap/uxap/ObjectPageLayout";

declare module "./ObjectPageLayout" {

    /**
     * Interface defining the settings object used in constructor calls
     */
    interface $ObjectPageLayoutSettings extends $ObjectPageLayoutSettings {
        example?: string;
    }

    export default interface ObjectPageLayout {

        // property: example
        getExample(): string;
        setExample(example: string): this;
    }
}

The ts error:

Type '$ObjectPageLayoutSettings' has no properties in common with type '$ObjectPageLayoutSettings'.ts(2559)

One solution could be to prefix the interfaces of the gen.d.ts file with a _ or other symbol to avoid naming problems:

import { $ObjectPageLayoutSettings } from "sap/uxap/ObjectPageLayout";

declare module "./ObjectPageLayout" {

    /**
     * Interface defining the settings object used in constructor calls
     */
    interface $_ObjectPageLayoutSettings extends $ObjectPageLayoutSettings {
        example?: string;
    }

    export default interface ObjectPageLayout {

        // property: example
        getExample(): string;
        setExample(example: string): this;
    }
}
import SAPObjectPageLayout from "sap/uxap/ObjectPageLayout";
import SAPObjectPageLayoutRenderer from "sap/uxap/ObjectPageLayoutRenderer";

/**
 * @namespace example.control
 */

export default class ObjectPageLayout extends SAPObjectPageLayout {

    constructor(idOrSettings?: string | $_ObjectPageLayoutSettings);
    constructor(id?: string, settings?: $_ObjectPageLayoutSettings);
    constructor(id?: string, settings?: $_ObjectPageLayoutSettings) {
        super(id, settings);
    }

    static readonly metadata = {
        "properties": {
            "example": {
                "type": "string"
            }
        }
    };

    renderer = SAPObjectPageLayoutRenderer;
}
akudev commented 2 years ago

Thanks for reporting! Will be fixed in the next release (with a "_1" suffix).

Regards Andreas

akudev commented 2 years ago

...which was just published: 0.5.0