Collection ReferenceError ... not defined


#1

I have an Angular 2 project and cannot get my reference to a collection.
Below are my 2 files in question.
The new Mongo IS called.

But Companies is not defined when I get to that line in Accounts.onCreateUser().

Error: Companies: ReferenceError: Companies is not defined???

/File: collections/Company.ts/
import {Mongo} from ‘meteor/mongo’;
export let Companies = new Mongo.Collection(‘company’);

/** File: server/addnewuser.ts **/
import {Companies} from ‘…/collections/Company’;

Accounts.onCreateUser((options, user) => {
if (! user.services.twitter) {
throw new Error(‘Expected login with Twitter only.’);
}
user._id = Random.id();

// Use the default hook's 'profile' behavior => user_profile
if (options.profile) {
    user.user_profile = options.profile;
    user.user_profile.imageurl = user.services.twitter.urlPath;
    user.roles = ["user", "admin"];
}

 // Create a company
let my_account:Account = <Account>{id: user._id};
my_account.handle = user.user_profile.handle;
my_account.type = "twitter";

let client:Client = <Client>{name: "_self"};
client.createdAt = new Date();
client.accounts = [my_account];
client.tags = ["TOFU", "MOFU", "BOFU"];

let company:Company = <Company>{name: "_self"};
//company._id = Random.id();
company.createdAt = new Date();
company.user_ids = [user._id];
company.clients = [client];

Companies.insert(company);
return user;

});


#2

Ah…

Changed the “export let Companies…”

to

“export var Companies…”

Worked … scoping issue.