gnaeus/knockout-decorators

Typescript build errors

thiagomajesk opened this issue · 5 comments

Hi! I'm having some errors (32) trying to use this package:

Error TS2304: Cannot find name 'KnockoutSubscription'
Error TS2304: Cannot find name 'KnockoutObservable'

knockout-decorator.d.ts:

image

I'm using Webpack through Laravel Mix and Visual Studio. Any hints why this is happening?
(Webpack build seems fine, but Visual Studio output doesn't even let me build the project)

I'm using:

  • "knockout": "^3.5.0",
  • "knockout-decorators": "^1.2.3",
  • "laravel-mix": "4.0.15"
  • "typescript": "^3.5.2"

and this is my tsconfig:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noEmitOnError": true,
    "sourceMap": true,
    "module": "commonjs",
    "target": "es5",
    "esModuleInterop": true
  }
}

Hi, seems that these are typings from @types/knockout. Since version 3.5.0 knockout has own typings, but they are using different names for interfaces, in this case they have Subscription instead of KnockoutSubscription, and Observable instead of KnockoutObservable.

Installing @types/knockout should help.

@trminator @types/knockout doesn't mix with the default typings from Knockout 3.5.0.
If you try to import ko from'knockout' in a typescript file you'll receive the following error:

Error TS2403: Subsequent variable declarations must have the same type. Variable 'ko' must be of type 'typeof import("C:/{project-path}/node_modules/knockout/build/types/knockout")', but here has type 'KnockoutStatic'.

@gnaeus I see that knockout-decorators is using Knockout 3.5, why the need to keep a reference to @types/knockout? Can't we drop it since it's not necessary anymore?

Sorry for long wait!

Is it breaking change or not? And should I release v2.0.0 or v1.3.0? Or even v3.5.0 (to synchronize versions with knockout package).

@gnaeus I think it's a breaking change because it prevents compilation if you're using both Knockout 3.5.0 and @types/knockout (the types are completely different as you can see here: knockout/knockout#2487). So technically, your package doesn't have a breaking change but a dependency does, making it virtually the same for users.

IMHO: I think v2.0.0 is just fine - mainly because I don't think it's interesting to restrict your package semver by synching versions with Knockout (something that makes sense for you doesn't make for them and vice versa). Also, we are getting Knockout 4 in the near feature and since they are aiming for backward compatibility it's very possible that they'll keep the same API. In other words, you can basically still have a v 2.x.x working for KO 4.

Folks, I've just released v2.0.0 with your fixes. Thanks a lot!