angularmeteorrolesangular-meteorangular2-meteor

alanning:role, importing issue in angular2-meteor


I have used alanning:role package by meteor, the Roles are working fine but the problem is I am getting warnings that "Cannot find name 'Roles".

Kindly help me with this problem. I have searched it everywhere.

Some people import it like "import { Roles } from 'alanning:roles';"

I have also tried this but still getting errors on this... Please help me and please don't commit it as in "asked issue". I am searching this issue from past two days, but I got no answer, please suggest me any help or please resolve this issue, thanks in advance.


Solution

  • The error you are facing is typing error. Its a meteor package and to notify typescript that your are using it your have to tell it by importing it.I had faced same kind of issue. actually you forgot to import

     import { Roles } from 'meteor/alanning:roles';
    

    in your collection file or publish file. Import it in your collection & publish file you will not face this typo error.

    Next thing if you are facing error Cannot find module 'meteor/alanning:roles' after importing that means meteor don't have definition for that package in typings.d.ts. Some of the packages don't have type definition file yet. you have to create your own typescript definition in typings.d.ts file or if you have new angular 2 meteor boilerplate that have @typings folder. just add this code in that file

    declare module "meteor/alanning:roles" {
      export module Roles {
        function userIsInRole(id?: any,value?: any): boolean{  }
        function addUsersToRoles(id?: any,value?: any): boolean{ }
      }
    }
    

    for other packages that give similar kind of error you can create your own definition.