How can I update a Knockout input file that is TypeScript 2.0 friendly?

I started working on updating the knockoutlibrary TypeScript declaration file , which is provided by the project DefinitelyTyped.

Some deprecated methods are used in the declaration file, and because of this, it is inconvenient to consume it in a TypeScript 2.0+ application.

The current declaration file contains an interface KnockoutStatic. Everything inside this should basically be exported using the export declare var/ format function(if I understand the new declaration file rules correctly). Then there should be an operator at the end of the file export as namespace ko;so that it can use it as an external module.

But rewriting the entire interface into this format is a lot of boring work, so I wonder if there is any trick or syntax to capture this entire interface and export it as they were at the top level.

I tried several things, for example, something like

declare var ko: KnockoutStatic;
export default ko;

But this, of course, led to two problems.

  • If I import using import ko from "knockout", then I can use my object kojust fine, but I don't have access to type interfaces KnockoutObservable<T>, etc.
  • If I import with import * as ko from "knockout;, then I have access to the interfaces through ko.KnockoutObservable<T>, which is completely fine, BUT, when I want to access the static material of the runtime, I get another level of the object ko, when like ko.ko.observableetc.

, KnockoutStatic , ko, , ( , TypeScript , ES6). , , .

, , ( , jQuery). , jQuery JQueryStatic, "" IMO.

+4

Source: https://habr.com/ru/post/1665801/


All Articles