Buslowicz / twc

TypeScript based, boilerplate-less, Polymer toolbox friendly Polymer Modules
32 stars 1 forks source link

Cannot alias imported behavior/mixin #106

Open tpluscode opened 7 years ago

tpluscode commented 7 years ago

I have multiple behaviors exported in same namespace:

// MixinOne.ts
export namespace Example {
  export function MixinOne<T extends Constructor<{}>>(superClass: T) {
    return class extends superClass { }
  }
} 

// MixinTwo.ts
export namespace Example {
  export function MixinTwo<T extends Constructor<{}>>(superClass: T) {
    return class extends superClass { }
  }
} 

It is not possible to >>correctly<< import both in one element's source by aliasing the namespace

import { Example as One } from './ExampleOne';
import { Example as Two } from './ExampleTwo';

export class ExampleElement extedns One.MixinOne(Two.MixinTwo(Polymer.Element)) {}

This will not work, because the alias is not correctly changed into the namespace. Instead of Example.MixinOne(Example.MixinTwo(Polymer.Element)) the aliases appear in generated output.

Not sure if's it's worth implementing this way although I don't think it's inherently bad to split the namespace this way.

A workaround is to import as but use the correct namespace and ignore TS errors/warning

export class ExampleElement extedns Example.MixinOne(Example.MixinTwo(Polymer.Element)) {}
Buslowicz commented 7 years ago

Should be fairly easy thing. Will do that when I get a moment.