我可以使用validator.ts驗證我的節點JS typescript應用程序。我跑了命令,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"/>
爲什麼heck是downvoted – mayooran
你的目標版本是什麼?如果你瞄準ES6它突然開始工作? – Paarth
我在打字稿中編寫我的代碼,並將其轉換爲ES5。我沒有使用ES6 – mayooran