铸造时打字稿错误
Typescript error when casting
我正在 运行 启动一个 运行Jasmine 和 Karma 的种子项目。
一切设置正确。
Webpack 启动应用程序 "npm start"
但是当我 运行 "npm test" Webpack 查看一个 .ts 文件然后加载 .spec.ts 文件时。
运行从种子项目
中使用此代码时出现错误
bundle is now VALID.
[32m06 10 2016 10:16:42.660:INFO [karma]:
[39mKarma v0.13.22 server started at http://localhost:9876/
[32m06 10 2016 10:16:42.664:INFO [launcher]:
[39mStarting browser PhantomJS
[32m06 10 2016 10:16:44.259:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]:
[39mConnected on socket /#YRouUOeCLSlLTu_KAAAA with id 23215732
PhantomJS 2.1.1 (Windows 7 0.0.0)
ERROR
SyntaxError: Unexpected token '<'
at C:/Development/ScratchApp/ScratchApp/src/test.ts:4
PhantomJS 2.1.1 (Windows 7 0.0.0)
错误是意外的标记“<”
在下面的test.ts个文件
// this file is only being used by karma
require('phantomjs-polyfill')
requireAll((<any>require).context("./", true, /spec.ts$/));
function requireAll(r: any): any {
r.keys().forEach(r);
}
有人能看出这个语法错误吗?
这道题的重点是:
at C:/Development/ScratchApp/ScratchApp/src/test.ts:4
这就是为什么您会收到意外标记“<”的原因,因为您的 TypeScript 文件在 requireAll
开头的行上有 <any>
。 JavaScript 不希望找到类型注释,这就是为什么它们在编译期间被全部删除的原因。
更新您的运行时代码以使用编译后的文件:
C:/Development/ScratchApp/ScratchApp/src/test.js
我正在 运行 启动一个 运行Jasmine 和 Karma 的种子项目。 一切设置正确。
Webpack 启动应用程序 "npm start" 但是当我 运行 "npm test" Webpack 查看一个 .ts 文件然后加载 .spec.ts 文件时。 运行从种子项目
中使用此代码时出现错误bundle is now VALID.
[32m06 10 2016 10:16:42.660:INFO [karma]:
[39mKarma v0.13.22 server started at http://localhost:9876/
[32m06 10 2016 10:16:42.664:INFO [launcher]:
[39mStarting browser PhantomJS
[32m06 10 2016 10:16:44.259:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]:
[39mConnected on socket /#YRouUOeCLSlLTu_KAAAA with id 23215732
PhantomJS 2.1.1 (Windows 7 0.0.0)
ERROR
SyntaxError: Unexpected token '<'
at C:/Development/ScratchApp/ScratchApp/src/test.ts:4
PhantomJS 2.1.1 (Windows 7 0.0.0)
错误是意外的标记“<” 在下面的test.ts个文件
// this file is only being used by karma
require('phantomjs-polyfill')
requireAll((<any>require).context("./", true, /spec.ts$/));
function requireAll(r: any): any {
r.keys().forEach(r);
}
有人能看出这个语法错误吗?
这道题的重点是:
at C:/Development/ScratchApp/ScratchApp/src/test.ts:4
这就是为什么您会收到意外标记“<”的原因,因为您的 TypeScript 文件在 requireAll
开头的行上有 <any>
。 JavaScript 不希望找到类型注释,这就是为什么它们在编译期间被全部删除的原因。
更新您的运行时代码以使用编译后的文件:
C:/Development/ScratchApp/ScratchApp/src/test.js