Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i import meteor-roles in typescript?

I'm writing a angular2-meteor application with typescript using angular2-meteor 0.5.4 and angular2 beta17.

I'm using accounts-password meteor package with with angular2-meteor-accounts-ui for ui representation.

I also installed the meteor package alanning:roles.

now I need to import Roles in typescript and i fail to do so because it doesn't contain a typescript definition file.

I searched on google and I found https://github.com/meteor-typescript/meteor-typescript-libs which container typescript definitions for many packages including Roles.

is this the way to go? am I missing something.

since I'm new to meteor and typescript i need reassurance that i'm following the right path.

thank you!

like image 233
ufk Avatar asked Mar 13 '23 10:03

ufk


1 Answers

import your Roles like so

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

Next, you need to add / update your custom typings file (meteor.d.ts in my case, which is autoloaded by 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;
  }
}
like image 108
vitkon Avatar answered Mar 15 '23 11:03

vitkon