Skip to content

Instantly share code, notes, and snippets.

@ducin

ducin/.gitignore

Last active Feb 3, 2020
Embed
What would you like to do?
typescript namespaces example
dist
node_modules
npm-debug.log
/// <reference path="person.ts" />
/// <reference path="nation.ts" />
import Person = People.Person;
import Nation = People.Nation;
const nation: Nation = new Nation();
nation.add(new Person('John', 'Lennon'));
console.log(nation.count);
namespace People {
export class Nation {
private population: Person[] = [];
add(person: Person): void {
this.population.push(person);
}
get count(): number {
return this.population.length;
}
}
}
{
"scripts": {
"compile": "./node_modules/.bin/tsc",
"start": "npm run compile && node dist/app.js"
},
"devDependencies": {
"typescript": "^2.0.9"
}
}
namespace People {
export class Person {
constructor(
private firstName: string,
private lastName: string
){}
}
}
{
"compilerOptions": {
"target": "es5",
"outFile": "dist/app.js"
},
"files": [
"app.ts"
]
}
@ducin

This comment has been minimized.

Copy link
Owner Author

@ducin ducin commented Nov 12, 2016

Run:

npm install
npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment