Monday 10 April 2017

Creating appropriate typings for node-simple-schema

I am atttempting to use node-simple-schema in my Meteor/Angular2/Typescript project and running into an issue with the typings. I tried opening an issue at the package to no avail:

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

from what I posted there: "Steps to reproduce: - Create a brand new project via 'git clone https://github.com/bsliran/angular2-meteor-base' - Prepare Packages

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

  • Create file '/both/models/shared.schema.ts'
  • Contents of file:

    import { SimpleSchema } from 'simpl-schema';

    export const MyValidationContext = new SimpleSchema({ name: { type: String } });

  • Generates Error:

.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)

  • Expected behavior: Named validation context exported for use elsewhere within the application.

  • What else I tried

1: dts-gen -m simpl-schema

2: typings install --save meteor-simple-schema --source global --global which imports the old, deprecated meteor-simple-schema typings. From there I copied the typings from /typings/globals/meteor-simple-schema and declared a new module simpl-schema in /typings.d.ts, where I pasted them. A few tweaks later, I'm mostly through all the compiler errors except the most important one:

TypeError: simpl_schema_1.SimpleSchema is not a function

Is there something I've missed or done incorrectly in my setup to get to this point? Is there a set of typings out there I haven't discovered yet? Is there a more straightforward way to declare the typings for the module? I've resigned myself to having to do it manually but can't figure out how to write the type that allows for new SimpleSchema, apparently.

Thanks in advance for any assistance.



via Quentin Kramer

No comments:

Post a Comment