I am creating a library in typescript that spreads across multiple files. I take all the classes and constants that I define, and import them into one module, which exports them all under one namespace. I just defined an interface, and I want to include it in the same namespace / module as all other parts of my library. But apparently I canβt.
Here is a simplified example:
/app.ts is the entry point of the application, everything I'm doing at the moment includes my MyLib library:
//app.ts import myLib = require("lib/MyLib/MyLib"); // this works fine
/lib/MyLib/MyLib.ts is a file in which I import all the things defined by MyLib and export them together:
// lib/MyLib/MyLib.ts import VehiclesImport = require("./transport/vehicles"); // error under VehiclesImport.IAutomobile, saying that VehiclesImport has no property IAutomobile export var IAutomobile = VehiclesImport.IAutomobile; export var Car = VehiclesImport.Car;
In / lib / MyLib / transport / vehicles.ts, I define several classes and interfaces of vehicles, here I just show IAutomobile and Car:
// lib/MyLib/transport/vehicles.ts export interface IAutomobile { weight: number } export class Car implements IAutomobile { weight = 3000 }
I tried to create a cool truck in MyLib.ts that implements IAutomobile correctly, and it works fine, without error messages. The problem only occurs when I want to access IAutomobile outside the "tools" statement.
I apologize if this looks like a "dump code", but in my opinion, this is a serious problem that I cannot access my interfaces except in the class declaration. I have been searching Google for the past two hours and have not found anything about this. Thanks for any help you can give me!
Change I understand that typescript interfaces are not part of the compiled javascript code, but this should not stop me from manipulating them in typescript.