简体   繁体   中英

imprt node_module in typescript (angular2) app

I try to load this module in my typescript add. First I added the npm package and the module has been installed correctly in my node_modules folder as simpl-schema . Since there are no typings for this package I added this line:

declare var SimpleSchema: any;

I tried to import the package with import * as SimpleSchema from 'simpl-schema'; and got the message Cannot find module 'simpl-schema' . I think a got this since simpl-schema doesn't contain type information but I'm not sure.

I found tons of questions regarding this topic here, on reddit and other forums with a lot of suggestions which doesn't work for my setup. So I'm wondering whats the right way to this.

You are correct that you're getting Cannot find module 'simpl-schema' because types are either not available, or types are not setup properly.

Using declare var SimpleSchema: any; in your ts says that SimpleSchema is a variable ( var ) of type any declared outside the scope of that file. The above will not impact the result of importing simpl-schema directly. An example would be adding something like declare const window: any; to get access to the window object, if it weren't already defined for you, elsewhere.

See here for a way to leverage the any type when looking to import modules that don't have types available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM