纯属个人学习,加深记忆使用。
命名空间
主要用于组织代码,避免命名冲突
使用关键词 namespace
命名空间内的类和方法也需要 export进行暴露
namespace a {
interface Animal {
name: string;
eat(str: string): void;
}
export class Dog implements Animal {
name: string;
constructor(name: string) {
this.name = name;
}
eat() {
console.log(this.name + "吃骨头");
}
}
}
let d = new a.Dog("哈士奇");
d.eat();