Kon*_*ski 4 asp.net-mvc visual-studio knockout.js typescript
我在Visual Studio中创建了一个新的空ASP MVC 5.0项目。我添加了以下nuget软件包:
我的tsconfig.json文件:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
Run Code Online (Sandbox Code Playgroud)
当我的项目设置为使用TypeScript 2.2并构建项目时,一切正常,但是如果我更改为使用任何较新的版本(例如2.7),则我会在敲除.d.ts文件中收到约34个错误,如下所示:
Property 'push' of type '(...items: T[]) => void' is not assignable to string index type 'KnockoutBindingHandler'
Property 'remove' of type '{ (item: T): T[]; (removeFunction: (item: T) => boolean): T[]; }' is not assignable to string index type 'KnockoutBindingHandler'
Run Code Online (Sandbox Code Playgroud)
要解决此问题,我从https://www.npmjs.com/package/@types/knockout下载了新的剔除定义,并替换了nuget添加的文件,现在没有任何错误。
我的问题:1.打字稿定义nuget包是否最新?2.如何配置Visual Studio项目以使用npm
打字稿定义nuget包是否最新?
否-nuget软件包中提供的基因敲除d.ts不会使用TypeScript编译器的较新版本进行编译,可能会破坏2.4或2.5左右,因此已过时。这个答案有关于/sf/answers/3189856001/的一些信息
如何配置Visual Studio项目以使用npm
我将卸载knockout.TypeScript.DefinitelyTyped nuget软件包,并确保〜\ Scripts \ typings \ knockout \ knockout.d.ts文件消失了。假设您已在计算机上安装了node / npm,请在webapp的根目录中执行以下操作
npm init
npm install --save @types/knockout
Run Code Online (Sandbox Code Playgroud)
那么像这样的.ts文件将正确编译(并且您应该在ko参考上获得intellisense)
import * as ko from 'knockout'
class Test {
name = ko.observable();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1494 次 |
| 最近记录: |