2017-06-05 55 views
2

我是Typescript和Angular 2的新手。我需要安裝npm依賴項並將其用於我的角度2應用程序。無法找到typings.d.ts並在角度2打字稿應用程序中聲明模塊

的依賴是https://www.npmjs.com/package/ng2-stomp-service

我已經安裝了必要的軟件包,但我需要添加以下到我的typings.d.ts文件

declare module 'stompjs'; 
declare module 'sockjs-client'; 

我無法找到typings.d.ts文件在我的項目。

我曾嘗試以下,到目前爲止,

npm install typings --global 
npm install @types/stompjs 
npm isntall @types/sockjs-client 
typings install dt~stompjs --save 
typings install dt~sockjs-client --save 

typings.json文件與內容,

{ 
    "dependencies": { 
    "sockjs-client": "registry:dt/sockjs-client#1.0.3+20160727010356", 
    "stompjs": "registry:dt/stompjs#2.3.0+20161111105645" 
    } 
} 

當我跑我的角2的應用程序與npm start它拋出的錯誤如下

ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (27,2): Member 'config' implicitly has an 'any' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (36,2): Member 'queuePromises' implicitly has an 'any[]' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (83,32): Parameter 'str' implicitly has an 'any' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (132,53): Parameter 'response' implicitly has an 'any' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (27,2): Member 'config' implicitly has an 'any' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (36,2): Member 'queuePromises' implicitly has an 'any[]' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (83,32): Parameter 'str' implicitly has an 'any' type. 
ERROR in D:/Userfiles/subramanians/projects/hand-cricket/node_modules/ng2-stomp-service/dist/stomp.service.ts (132,53): Parameter 'response' implicitly has an 'any' type. 

我不確定是什麼原因造成的問題,我猜我t是因爲我還沒有申報模塊typings.d.ts

請指教。謝謝。

回答

1

好像你的Typescript編譯器試圖從node_modules目錄編譯文件。

請確保你在你的tsconfig.json文件這不包括規則:

{ 
    "compilerOptions": {}, 
    "exclude": [ 
    "node_modules" 
    ] 
} 

順便說一句。你只需要一個@typestypings。第二個不推薦使用,你需要的只是你開發依賴中包含的正確的@types包。希望能幫助到你!

編輯:我覺得不應該在NPM包中的任何打字稿文件,所以我創建與此庫的github上固定一個主題:https://github.com/devsullo/ng2-STOMP-Over-WebSocket/issues/5

3

如果你不使用的角度新版本,你可以在您的項目中找不到typings.d.ts文件。我的建議是採用了棱角分明CLI https://cli.angular.io/

0

我的兩個美分,這個對話,更新項目:

在你tsconfig.json文件請確保你有你的typings.d.ts正道文件

「typeRoots」:[ 「node_modules/@類型」, 「../src/typings.d.ts」 ],

相關問題