1

I am trying to use typescript in part of my angular application. I have a ts file describing a class User:

module App.Tools {
    export class User {
        name: string;
        constructor(name: string) {
            this.name = name;
        }
    }
}

And in my JS file (es2015) I try to import the class User:

import  {User} from 'User.ts';

export default class AuthFactory {
    /**
     * @param  {[type]}
     * @return {[type]}
     */
    constructor($firebaseAuth) {
        this.ref = new Firebase("...");

        // create an instance of the authentication service
        this.auth = $firebaseAuth(this.ref);

        var authData = this.auth.$getAuth();

        if (authData) {
            this.currentUser = new User(authData.google.displayName, authData.provider);
        } else {
            this.currentUser = null;
        }
    }
}

This doesn't work as I get an error : "User is not defined".

I am using gulp with browserify, tsify and babel.

1
  • 1
    .ts extension does not belong to import statement. Commented Jan 26, 2016 at 11:31

1 Answer 1

1

I think you need an "external" typescript module in "User.ts" file:

class User {
    name: string;
    constructor(name: string) {
        this.name = name;
    }
}

export = User;

Update 1

Using internal modules:

module App.Tools {
    export class User {
        name: string;
        constructor(name: string) {
            this.name = name;
        }
    }
}

export = App.Tools;

To use this in import:

import { User } from 'User.ts';
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, Thanks for the reply. Unfortunately your solution is not working. THe line 'this.currentUser = new User(authData.google.displayName, authData.provider);' doesn't seem to work
Update: I've found that with nodejs it is not possible to use internal modules. Must stick with external modules.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.