我正在使用 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/