2016-05-17 68 views
-1

我可以使用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"/> 
+0

爲什麼heck是downvoted – mayooran

+0

你的目標版本是什麼?如果你瞄準ES6它突然開始工作? – Paarth

+0

我在打字稿中編寫我的代碼,並將其轉換爲ES5。我沒有使用ES6 – mayooran

回答

1

我希望你不要介意,如果我把它作爲答案來解決,因爲不幸的是這看起來很不合適。

發生此錯誤是因爲您試圖定位ES5並且未定義Promise接口。它在the .d.ts file typescript uses for es6中定義。

Validator.ts明確指出使用ES6功能。你在評論中提到你不能瞄準ES6。

你選擇我看到他們的方式:

  1. 目標ES6。請注意,這並不意味着你是被困在那裏,看到選項4
  2. 不要使用Validator.ts
  3. 使用ES6-墊片上Validator.ts npm page
  4. 使用的建議像巴貝爾從去一個transpiler打字稿> ES6> ES5。
+0

是否有任何其他驗證工具可以使用? – mayooran

相關問題