2017-04-11 23 views
1

我在我的Meteor/Angular2/Typescript項目中試圖使用node-simple-schema,並遇到類型問題。我試圖在包打開的問題無濟於事:從我貼有爲節點簡單模式創建適當的類型

https://github.com/aldeed/node-simple-schema/issues/90

: 「重現步驟: - 通過‘git的克隆https://github.com/bsliran/angular2-meteor-base’ 創建一個全新的項目 - 準備包

meteor update 
meteor update --all-packages 
meteor npm update 
meteor remove insecure 
meteor remove autopublish 
meteor add aldeed:collection2-core 
meteor npm install --save simpl-schema 
meteor add aldeed:schema-deny 
meteor add aldeed:schema-index 
meteor add accounts-password 
meteor add alanning:roles 
  • 創建文件 '/both/models/shared.schema.ts'
  • 續文件的尾部:

    從'simpl-schema'導入{SimpleSchema};

    出口常量MyValidationContext =新SimpleSchema({ 名稱:{ 類型:字符串 } });

  • 生成錯誤:

.meteor/packages/meteor-tool/.1.4.3_2.13aht4s++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280 W20170403-05:53:05.591(0)? (STDERR) throw(ex); W20170403-05:53:05.591(0)? (STDERR)^W20170403-05:53:05.591(0)? (STDERR) W20170403-05:53:05.592(0)? (STDERR) TypeError: simpl_schema_1.SimpleSchema is not a function W20170403-05:53:05.592(0)? (STDERR) at meteorInstall.both.models.shared.schema.js (both/models/shared.schema.ts:6:35) W20170403-05:53:05.592(0)? (STDERR) at fileEvaluate (packages/modules-runtime.js:197:9) W20170403-05:53:05.592(0)? (STDERR) at require (packages/modules-runtime.js:120:16) W20170403-05:53:05.592(0)? (STDERR) at server/main.ts:4:22 W20170403-05:53:05.593(0)? (STDERR) at /var/webapps/schema/.meteor/local/build/programs/server/boot.js:303:34 W20170403-05:53:05.593(0)? (STDERR) at Array.forEach (native) W20170403-05:53:05.594(0)? (STDERR) at Function..each..forEach (/home/blah/.meteor/packages/meteor-tool/.1.4.3_2.13aht4s++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) W20170403-05:53:05.594(0)? (STDERR) at /var/webapps/schema/.meteor/local/build/programs/server/boot.js:128:5 W20170403-05:53:05.594(0)? (STDERR) at /var/webapps/schema/.meteor/local/build/programs/server/boot.js:352:5 W20170403-05:53:05.595(0)? (STDERR) at Function.run (/var/webapps/schema/.meteor/local/build/programs/server/profile.js:510:12)

  • 預期的行爲:在應用程序中導出的其他地方使用 命名驗證環境。

  • 還有什麼我試圖

1:dts-gen -m simpl-schema

2:typings install --save meteor-simple-schema --source global --global其中進口舊的,過時流星簡單的模式分型。從那裏我複製了/ typings/globals/meteor-simple-schema中的類型,並在/typings.d.ts中聲明瞭一個新的模塊簡單模式,我粘貼了它們。一些調整後,我主要是通過除最重要的所有編譯器錯誤:

類型錯誤:simpl_schema_1.SimpleSchema不是一個函數

有什麼我已經錯過了或者我的設置不正確完成要達到這一點?有沒有我還沒有發現的一組類型?有沒有更直接的方式來聲明模塊的類型?我已經辭職了,不得不手動去做,但不知道如何編寫允許new SimpleSchema的類型,顯然。

感謝您的任何援助。

回答

0

您是否嘗試過沒有讚譽,如README所示?

import SimpleSchema from 'simpl-schema'; 

該軟件包導出default member

+0

我有;我得到一個錯誤,它沒有導出默認成員tho我同意你可以看到一個導出在/simpl-schema/main.js中。現在再試一次,爲了安全起見。 –

+0

both/collections/shared/shared.schema.ts(8,8):Module'「simpl-schema」'沒有默認導出。但是你知道什麼,_it不是crashing_,它只是一個編譯器錯誤。我想知道爲什麼編譯器無法看到,但它確實似乎正在工作,流星現在加載並運行,這意味着我可以進一步排除故障......感謝讓我再試一次。 –

+0

您的類型定義可能不會提及默認導出。 TypeScript依賴於這些類型的代碼分析,但不好的類型不影響底層的JS代碼。 – ghybs