I will provide an example how to reference classes from other .ts files.
In this example we have four .ts files which are modules by default (external modules), except the fourth file app.ts
Typescript Modules
In TypeScript, just as in ECMAScript 2015, any file containing a
top-level import or export is considered a module. Conversely, a file
without any top-level import or export declarations is treated as a
script whose contents are available in the global scope (and therefore
to modules as well).
Example:
We have a class Man and a class Woman which inherit from class Human.
In app.ts we create an instance of Man.
Human.ts
export class Human {
public Name: string;
constructor(name: string) {
this.Name = name;
}
public WhatIsMyName() {
console.log(`I am ${this.Name}`);
return this.Name;
}
}
Man.ts
import { Human } from "./Human";
export class Man extends Human {
constructor(name: string) {
super(name);
}
}
Woman.ts
import { Human } from "./Human";
export class Woman extends Human {
constructor(name: string) {
super(name);
}
}
YourApp.ts
import { Man } from "./man";
const man = new Man("Billy The Kid");
man.WhatIsMyName();