1

I am very new to TypeScript and I've run into a problem that I can't quite figure out...

I am using a library called TypeLite that will take my C# POCO's and convert them into TypeScript classes.

It is a T4 template that generates a file called TypeLite.Net4.d.ts, which as I understand, .d files are definition files that are loaded automatically.

The generated code looks like this:

declare module Models {
    export class LoginModel {
        password: string;
        rememberMe: boolean;
        userName: string;
    }
}

In my component, I can access Models.LoginModel just fine and it doesn't give me any compiler errors (using Visual Studio).

However, when I try and run it, I get:

EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: ReferenceError: Models is not defined
ORIGINAL STACKTRACE:
ReferenceError: Models is not defined
    at new LoginComponent 

Here is my LoginComponent:

import { Component } from 'angular2/core';

@Component({
    selector: 'login',
    templateUrl: './app/login/login.html'
})

export class LoginComponent {
    model: Models.LoginModel = new Models.LoginModel();
}

What am I doing wrong here?

1 Answer 1

2

you have not imported Model into your LoginComponent

   import { Model } from 'path to Model module';

The intellisense you might be getting because of the definition file, but to use it at run time you have to import the class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.