Trying to add a class wrapped in a module declaration to angular

218 Views Asked by At

I used Typewriter to create an typescript class from my C# code. When I try to reference it in my angular project via import it says module does not exist or namespace not recognized if I use namespace.

What is the proper way to add class to my project so I can use it in other files?

module Budget.Infrastructure.Model {
        // $Classes/Enums/Interfaces(filter)[template][separator]
        // filter (optional): Matches the name or full name of the current item. * = match any, wrap in [] to match attributes or prefix with : to match interfaces or base classes.
        // template: The template to repeat for each matched item
        // separator (optional): A separator template that is placed between all templates e.g. $Properties[public $name: $Type][, ]
    
        // More info: http://frhagn.github.io/Typewriter/
    
        
        export class User {
            
            // ID
            public id: string = null;
            // FIRSTNAME
            public firstName: string = null;
            // LASTNAME
            public lastName: string = null;
            // EMAIL
            public email: string = null;
        }
    }
1

There are 1 best solutions below

3
Edoardo On

you have to export the module

export module Budget.Infrastructure.Model {
        // $Classes/Enums/Interfaces(filter)[template][separator]
        // filter (optional): Matches the name or full name of the current item. * = match any, wrap in [] to match attributes or prefix with : to match interfaces or base classes.
        // template: The template to repeat for each matched item
        // separator (optional): A separator template that is placed between all templates e.g. $Properties[public $name: $Type][, ]
    
        // More info: http://frhagn.github.io/Typewriter/
    
        
        export class User {
            
            // ID
            public id: string = null;
            // FIRSTNAME
            public firstName: string = null;
            // LASTNAME
            public lastName: string = null;
            // EMAIL
            public email: string = null;
        }
}

and you can import like this

import {Budget} from "./test";
import User = Budget.Infrastructure.Model.User;