HerringtonDarkholme / av-ts

A modern, type-safe, idiomatic Vue binding library
MIT License
216 stars 11 forks source link

Mixin type definition seems broken in ts 2.4 #67

Closed thorning closed 7 years ago

thorning commented 7 years ago

I think some of the changes to type definition in 2.4 broke the mixin ts 2.4.

//The ComponentWithMixin no longer have the right signature
@Component({
  name : 'no-longer-working',
  components : {
    ComponentWithMixin
  },
})
...

// it still works if the subcomponent does not use Mixin
@Component({
  name : 'still-working',
  components : {
    ComponentWithoutMixin
  },
})
...

Both work if I revert ts to 2.3.

HerringtonDarkholme commented 7 years ago

Thanks for reporting! I will take a look.

HerringtonDarkholme commented 7 years ago

Strangely I cannot reproduce. Could you provide an example with ComponentsWithMixin and ComponentsWithoutMixin definition?

thorning commented 7 years ago

The following compiles in ts 2.3.2 but not in 2.4.2 for me:

@Trait class TestTrait extends Vue {}

@Component({
  name : 'mixin-component'
})
class MixinComponent extends Mixin(TestTrait) {

}

@Component({
  name : 'depend-on-mixin-component',
  components : {
    MixinComponent
  }
})
class DependOnMixin extends Vue {

}

I get the following error in 2.4.2:

Argument of type '{ name: string; components: { MixinComponent: typeof MixinComponent; }; }' is not assignable to parameter of type 'ComponentOptions<Vue> | undefined'.
  Type '{ name: string; components: { MixinComponent: typeof MixinComponent; }; }' is not assignable to type 'ComponentOptions<Vue>'.
    Types of property 'components' are incompatible.
      Type '{ MixinComponent: typeof MixinComponent; }' is not assignable to type '{ [key: string]: typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions | AsyncComponent...'.
        Type '{ MixinComponent: typeof MixinComponent; }' is not assignable to type '{ [key: string]: typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions | AsyncComponent...'.
          Property 'MixinComponent' is incompatible with index signature.
            Type 'typeof MixinComponent' is not assignable to type 'typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions | AsyncComponent'.
              Type 'typeof MixinComponent' is not assignable to type 'AsyncComponent'.
                Type 'typeof MixinComponent' provides no match for the signature '(resolve: (component: Component) => void, reject: (reason?: any) => void): void | typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions | Promise<Component>'.

I tried looking though the definitions, but not quite sure what the problem is. It might be that VClass, which the Mixin function returns, does not extend Vue or ComponentOption? I cant quite wrap my head around it though.

HerringtonDarkholme commented 7 years ago

It seems quite hard to fix. The problem is mixin pattern cannot handle static property well...

HerringtonDarkholme commented 7 years ago

I come up with a method to add static method! Released as 0.9.1.