【问题标题】:Creating appropriate typings for node-simple-schema为节点简单模式创建适当的类型
【发布时间】:2017-04-11 10:53:36
【问题描述】:

我正在尝试在我的 Meteor/Angular2/Typescript 项目中使用 node-simple-schema,但遇到了打字问题。我尝试在包中打开问题无济于事:

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

根据我在那里发布的内容: “重现步骤: - 通过 'git clone 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 };

    export const MyValidationContext = new 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/纤维/future.js:280 W20170403-05:53:05.591(0)? (STDERR)抛出(前); W20170403-05:53:05.591(0)? (STDERR) ^ W20170403-05:53:05.591(0)? (STDERR) W20170403-05:53:05.592(0)? (STDERR) 类型错误: simpl_schema_1.SimpleSchema 不是函数 W20170403-05:53:05.592(0)? (STDERR) 在 meteorInstall.both.models.shared.schema.js (两者/模型/shared.schema.ts:6:35)W20170403-05:53:05.592(0)? (STDERR) 在 fileEvaluate (packages/modules-runtime.js:197:9) W20170403-05:53:05.592(0)? (STDERR) 在需要时 (packages/modules-runtime.js:120:16) W20170403-05:53:05.592(0)? (STDERR) 在 server/main.ts:4:22 W20170403-05:53:05.593(0)? (STDERR) 在 /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) 在 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) 在 /var/webapps/schema/.meteor/local/build/programs/server/boot.js:128:5 W20170403-05:53:05.594(0)? (STDERR) 在 /var/webapps/schema/.meteor/local/build/programs/server/boot.js:352:5 W20170403-05:53:05.595(0)? (STDERR)在 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,我将它们粘贴到了那里。稍作调整后,除了最重要的错误之外,我主要解决了所有编译器错误:

TypeError: simpl_schema_1.SimpleSchema 不是函数

为了达到这一点,我在设置中是否遗漏了什么或做错了什么?那里有一组我还没有发现的类型吗?有没有更直接的方法来声明模块的类型?我已经让自己不得不手动执行此操作,但显然无法弄清楚如何编写允许new SimpleSchema 的类型。

提前感谢您的帮助。

【问题讨论】:

    标签: node.js angular typescript meteor


    【解决方案1】:

    您是否尝试过没有像README 所示的荣誉?

    import SimpleSchema from 'simpl-schema';
    

    包导出default member

    【讨论】:

    • 我有;我收到一个错误,它没有导出默认成员,但我同意您可以在 /simpl-schema/main.js 中看到导出的成员。现在再试一次,以防万一。
    • both/collections/shared/shared.schema.ts (8, 8):模块 '"simpl-schema"' 没有默认导出。但是你知道吗,它没有崩溃,它只是一个编译器错误。我想知道为什么编译器看不到这一点,但它似乎确实在工作,并且 Meteor 现在加载并运行,这意味着我可以进一步排除故障......感谢让我再试一次。
    • 您的类型定义可能没有提到默认导出。 TypeScript 依赖这些类型进行代码分析,但错误的类型不会影响底层 JS 代码。
    猜你喜欢
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    相关资源
    最近更新 更多