I am creating an Angular2-Meteor app, starting with the Socially tutorial. I am trying to implement user Roles using alanning:roles and matb33:collection-hooks. The solution would be similar to that proposed here. The only difference would be that Angular 2 requires typescript definitions for Roles and Collection-Hooks. I have found meteor-typescript-libs, which has a definition for Roles that seems to work. However, the only resource for collection-hooks I found was typed-meteor-collection-hooks. I tried referencing index.d.ts by copy/pasting the file into my project, but I still get the following error:
server/imports/accounts.ts (30, 14): Property 'after' does not exist on type 'Collection < User >'.
At the following line:
Meteor.users.after.insert(function (userId, doc) {
if (doc.profile.type === "basic") {
Roles.addUsersToRoles(doc._id, [ROLES.Basic])
} else if (doc.profile.type === "admin") {
Roles.addUsersToRoles(doc._id, [ROLES.Admin])
} else if (doc.profile.type === "manager") {
Roles.addUsersToRoles(doc._id, [ROLES.Manager])
}});
I am new to typescript, and it's not clear to me how I should implement type definitions for Meteor Packages. Clearly, my approach is wrong. Does anyone have any experience with roles and collection-hooks in Meteor-Angular2?
UPDATE: It seems like the Meteor.users.after.insert() code is executing after inserting a user, despite the error. I am continuing development, but would appreciate a solution for removing the error.
Have you tried installing the typings from npm?
https://www.npmjs.com/package/@types/meteor-collection-hooks
Don't forget to also add to your tsconfig "types" array like:
"types": [
"@types/meteor-collection-hooks"
]