简体   繁体   English

alanning:角色,在angular2-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" . 我已经使用了流星的 alanning:role包, 角色工作正常,但问题是我收到警告"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';" 有些人像"import { Roles } from 'alanning:roles';"导入它"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. 我过去两天都在搜索这个问题,但是我没有回答,请给我任何帮助,或者请提前解决这个问题。

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 . 接下来的事情如果你遇到错误导入后Cannot find module 'meteor/alanning:roles'意味着meteor在typings.d.ts没有该包的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. 你必须在typings.d.ts文件中创建自己的打字稿定义,或者你有新的带有@typings文件夹的角度2流星样板。 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. 对于提供类似错误的其他包,您可以创建自己的定义。

There is a simpler way to import meteor packages in typescript without writing your own declarations. 有一种更简单的方法可以在typescript中导入meteor包而无需编写自己的声明。 Most of the types are defined here 这里定义了大多数类型

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/meteor https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/meteor

Install NPM module that has types defined. 安装已定义类型的NPM模块。

meteor npm install --save @types/meteor-roles

Import the types in your modules 导入模块中的类型

import { } from '@types/meteor-roles';

Now, you can use Roles type for methods like addUsersToRoles() etc. 现在,您可以为addUsersToRoles()等方法使用Roles类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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