michaelolof / typescript-mix

A tweaked implementation of TypeScript's default applyMixins(...) idea using ES7 decorators
https://www.npmjs.com/package/typescript-mix
86 stars 8 forks source link

[ts] Member 'this' implicitly has an 'any' type #5

Closed glebkudr closed 5 years ago

glebkudr commented 5 years ago

When I use code from the example it throws me an error on this statement: [ts] Member 'this' implicitly has an 'any' type

class Shopperholic {
    @use( Buyer, Transportable ) this

    price = 2000;
    distance = 140;
  }

I have made the "noImplicitAny": false in tsconfig and all is ok but wonder - is it a valid behaviour?

michaelolof commented 5 years ago

Good Morning.

A lot of libraries utilizing decorators with TypeScript classes also have this problem. The typescript compiler is very strict by default (and that is a good thing)

The "noImplicitAny: false" tweak works just fine, but i'm not a fan of this approach.

You could also just explicitly give the this property an "any" type that way you typescript compiler is still very strict.

So your code becomes.

class Shopperholic {
  @use( Buyer, Transportable ) this:any
  price = 2000;
  distance = 140;
}