TypeScript with KnockoutJS

后端 未结 6 1418
粉色の甜心
粉色の甜心 2020-12-22 16:28

Is there any sample of using TypeScript with KnockoutJS? I\'m just curious as to how they would work together?

Edit

Here is what I have, seems to work

6条回答
  •  梦毁少年i
    2020-12-22 16:38

    Ok so just use the following command to import the knockout types or tds.

    npm install @types/knockout
    

    This will create a @types directory in your projects node_modules directory and the index knockout type definition file will be in a directory named knockout. Next, through a triple-slash reference to the types file. This will give great IDE and TypeScript features.

    /// 
    

    Finally, just use a declare statement to bring the ko variable into scope. This is strongly-typed so hello intellisense.

    declare var ko: KnockoutStatic;
    

    So now you can use KO just like in your javascript files.

    Hope this helps.

提交回复
热议问题