我试图在我的Node JS打字稿应用程序中使用validator.ts进行验证。我跑了命令,
npm install validator.ts --save
并安装它。现在,当我运行gulp来构建我的应用程序时,它会在validator.ts文件中抛出以下错误。
[14:58:24] Starting 'npm'...
[14:58:25] Compiling TypeScript files using tsc version 1.8.7
[14:58:27] [tsc] > node_modules/validator.ts/Validator.d.ts(20,73): error TS2304
: Cannot find name 'Promise'.
[14:58:27] [tsc] > node_modules/validator.ts/Validator.d.ts(34,34): error TS2304
: Cannot find name 'Promise'.
[14:58:27] [tsc] > node_modules/validator.ts/Validator.d.ts(43,84): error TS2304
: Cannot find name 'Promise'.
[14:58:27] [tsc] > src/main/EdgeNode.ts(59,27): error TS2346: Supplied parameter
s do not match any signature of call target.
[14:58:27] Failed to compile TypeScript: Error: tsc command has exited with code
:2
[14:58:27] Finished 'npm' after 2.4 s
[14:58:27] Finished 'build-scripts' after 5.73 s
[14:58:27] Starting 'test'...
[14:58:27] Starting 'clean-source-tmp'...
[14:58:27] Finished 'clean-source-tmp' after 3.82 ms
[14:58:27] Starting 'coverage-build'...
[14:58:27] Starting 'clean-source-tmp'...
[14:58:27] Finished 'clean-source-tmp' after 3.72 ms
[14:58:27] Starting 'tmp-scripts'...
G:/Projects/Kube2/edge-node-sdk-js/node_modules/validator.ts/Validator.d.ts(20,7
3): error TS2304: Cannot find name 'Promise'.
[14:58:28] [Typescript] TypeScript error: G:/Projects/Kube2/edge-node-sdk-js/nod
e_modules/validator.ts/Validator.d.ts(20,73): error TS2304: Cannot find name 'Pr
omise'.
G:/Projects/Kube2/edge-node-sdk-js/node_modules/validator.ts/Validator.d.ts(34,3
4): error TS2304: Cannot find name 'Promise'.
[14:58:28] [Typescript] TypeScript error: G:/Projects/Kube2/edge-node-sdk-js/nod
e_modules/validator.ts/Validator.d.ts(34,34): error TS2304: Cannot find name 'Pr
omise'.
G:/Projects/Kube2/edge-node-sdk-js/node_modules/validator.ts/Validator.d.ts(43,8
4): error TS2304: Cannot find name 'Promise'.
[14:58:28] [Typescript] TypeScript error: G:/Projects/Kube2/edge-node-sdk-js/nod
e_modules/validator.ts/Validator.d.ts(43,84): error TS2304: Cannot find name 'Pr
omise'.
src\main\EdgeNode.ts(59,27): error TS2346: Supplied parameters do not match any
signature of call target.
[14:58:28] [Typescript] TypeScript error: src\main\EdgeNode.ts(59,27): error TS2
346: Supplied parameters do not match any signature of call target.
[14:58:28] TypeScript: 4 semantic errors
我在这里做错了什么?请指教。
我看到了一些类似的问题,并将以下几行附加到我正在验证的主要课程中。但它仍然无济于事。
/// <reference path="../../node_modules/class-validator/Validator.d.ts"/>
/// <reference path="../../node_modules/class-validator/index.d.ts"/>
答案 0 :(得分:1)
我希望你不介意我把它作为一个答案,因为不幸的是,这似乎是最终的。
发生此错误是因为您尝试定位ES5并且未定义Promise接口。它在the .d.ts file typescript uses for es6中定义。
Validator.ts明确指出使用ES6功能。你在评论中提到你不能以ES6为目标。
您选择我的方式: