TypeScriptについて頭を悩ませようとしているだけです。
animals.ts次のようなモジュールがあるとします。
export module Animals {
export interface Animal {
name(): void;
}
export class Elephant implements Animal {
constructor() {
}
public name() {
console.log("Elephant");
}
}
export class Horse implements Animal {
constructor() {
}
public name() {
console.log("Horse");
}
}
}
そして、このモジュールを別のファイルで使用したいanimals_panel.ts:
import animals = require("animals")
module AnimalPanel {
var animal = new animals.Animals.Elephant();
animal.name();
}
- を使用しなければならないのは少し奇妙に思えますが
animals.Animals.Elephant()、予想していたでしょうAnimals.Elephant()。私は何か間違ったことをしていますか、それともこれは正しい行動ですか? import animals = require("animals")モジュール内にインポートすることは可能AnimalPanelですか (これを行おうとするとエラーが発生します)?