1

Current situation:

There is a class defined in:

lib/components/widgets/MyWidget.ts:

export class MyWidget {

    public property1: string;
    /* ... more properties ... */

}

It gets compiled to javascript, bundled with the other files as a reult of lib-min.js

So because it was in the lib/components/widgets/MyWidget.ts i have made a definition "collection" file (mydefinition.d.ts) like:

declare module "lib/components/widgets" {
    export class MyWidget {

        /* documentation of property1 */
        public property1: string;

        /* ... more properties ... */
    }
}

interface MyOption {/* ... */}

In this way it can be used like (of course after including lib-min.js into the page):

import { MyWidget } from "lib/components/widgets/MyWidget";

let myInstance = new MyWidget();

Problem:

I think it's obvious that maintaining this kind of duplication is overwhelming and can cause mistakes easily. Also after upgrading to typescript 2+ (from 1.8.9) i get several compile errors for "duplicate identifiers", and generally it is not working like before.

  • I could make an interface like IMyWidget and expose that to public, but then the implementation is missing and can not create with new
  • I could delete the "declare module..." from the mydefinition.d.ts but then the module loader won't find the module (because r.js optimizer names the module from it's path)

Question

Is there a clean and "cheap" way to solve this (and avoid code duplication if possible)?

ex4cutor
  • 23
  • 4

0 Answers0