meteor - 我如何在 typescript 中导入 meteor 角色?

标签 meteor typescript meteor-accounts

我正在使用 angular2-meteor 0.5.4 和 angular2 beta17 编写带有 typescript 的 angular2-meteor 应用程序。

我正在使用 accounts-password meteor 包和 angular2-meteor-accounts-ui 用于 ui 表示。

我还安装了 meteor 包 alanning:roles

现在我需要在 typescript 中导入 Roles 但我没有这样做,因为它不包含 typescript 定义文件。

我在谷歌上搜索并找到了 https://github.com/meteor-typescript/meteor-typescript-libs 许多包的容器 typescript 定义,包括角色。

这是要走的路吗?我错过了什么吗?

因为我是 meteor 和 typescript 的新手,所以我需要确保我走的是正确的道路。

谢谢!

最佳答案

像这样导入你的角色

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

接下来,您需要添加/更新您的自定义类型文件(在我的例子中是 meteor.d.ts,它由 Meteor 自动加载)

declare module "meteor/alanning:roles" {
  export module Roles {
    function createRole(roleName: string): string;
    function deleteRole(roleName: string): void;
    function addUsersToRoles(users: any, roles: any, groups?: string): void;
    function removeUsersFromRoles(users: any, roles: any): void;
    function userIsInRole(user: any, roles: any): boolean;  //user can be user ID or user object
    function getRolesForUser(userId: string): string[];
    function getAllRoles(): Mongo.Cursor<RolesDAO>;
    function getUsersInRole(roleName: string): Mongo.Cursor<RolesDAO>;
    var GLOBAL_GROUP: string;
  }
}

关于meteor - 我如何在 typescript 中导入 meteor 角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36997134/

相关文章:

Meteor模板层次结构和路由逻辑冲突

javascript - 我简单的 meteor 代码有什么问题

javascript - 如何在不转换为 Angular 中的字符串的情况下在多部分/表单数据请求中发送对象

Meteor 帐户 - 谷歌内部服务器错误,适用于本地但不适用于 EC2

angular - 使用 [routerLinkActive] 生成 'error on data.split'

sequelize.Model.Update 的 Typescript 接口(interface)不正确?

javascript - UnderscoresJS _.pluck 与 Meteor 用户集合的用法

Meteor.call 在助手内部不是响应式(Reactive)的

Meteor.http.post 设置小写的 'host' header 。我如何覆盖它?

forms - 使用相同的表单进行插入和编辑