I am attempting to update my knockout typings, as latest version of typescript is is detecting problems with the older ones.
The problem comes with trying to get the knockout and knockout.es5 typings working together.
I am using VS2017 and a tsconfig file.
I install knockout typings like so:
typings install dt~knockout
and then I install the knockout-es5 typings like so:
typings install dt~knockout-es5 --global
After I install the knockout es5 typings, they have compile errors because there is no such type KnockoutObservable<T>
.
So I added this to the top of the knockout-es5 typings:
/// <reference path="../../modules/knockout/index.d.ts" />
import * as ko from "knockout";
and changed KnockoutObservable<any>
to ko.Observable<any>
and it now compiles.
So.. now I want use these typings to create a knockout view model, so in a new typescript file:
import * as ko from "knockout"
class Foo {
Id: number
Name: string
constructor(id: number, name: string) {
this.Id = id;
this.Name = name;
ko.track(this);
}
}
This results in compile error as track
does not exist on typeof ko
This is because ko is imported from the knockout
module, which is exported from the knockout
typings, however track
is a method that is meant to be added by the knockout-es5
typings, but isn't. How do I amend the knockout-es5 typings file further to get this to work?
Update: I have tried adding this to the bottom of the knockout.es5/index.d.ts file:
declare var ko: KnockoutStatic;
declare module "knockout-es5" {
export = ko;
}
And in my typescript file I am trying:
import * as ko from "knockout-es5"
But the import statement won't compile: It says cannot find module knockout-es5
.
I have also tried this:
import * as ko from "../typings/globals/knockout.es5/index"
This seems to work, but then I have to change my code to do this, which seems wrong to me (Note the additional .ko
:
class Application {
Id: number
Name: string
constructor(id: number, name: string) {
this.Id = id;
this.Name = name;
ko.ko.track(this);
}
}
And also once I do that, I can no longer resolve the original ko
types like ko.Observable
.