我正在使用angular2-meteor 0.5.4和angular2 beta17编写带有打字稿的angular2-meteor应用程序。
我正在使用accounts-password
meteor包与angular2-meteor-accounts-ui
进行ui表示。
我还安装了meteor包alanning:roles
。
现在我需要在typescript中导入Roles
,但我没有这样做,因为它不包含打字稿定义文件。
我在谷歌上搜索过,我发现https://github.com/meteor-typescript/meteor-typescript-libs 许多包的容器打字稿定义,包括角色。
这是要走的路吗?我错过了什么。
因为我是流星和打字稿的新手所以我需要保证我正在走正确的道路。 谢谢你!答案 0 :(得分:2)
像这样导入你的角色
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;
}
}
答案 1 :(得分:1)
有一种更简单的方法可以在打字稿中导入流星雨包。大部分类型在此处定义
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/meteor
安装已定义类型的NPM模块。
meteor npm install --save @types/meteor-roles
导入模块中的类型
import { } from '@types/meteor-roles';
现在,您可以将Roles类型用于addUsersToRoles()等方法。