使用tsc 1.8.9 ...爲什麼這些導入不起作用?我認爲TypeScript實現了ES6模塊語法?使用TypeScript默認導入
「類/ person.ts」
export default class Person {
protected _name: string;
protected _language: string;
constructor(name: string) {
this._name = name;
this.hello();
}
public hello() {
console.log("Hello, " + this._name);
console.log("Lang: " + this._language);
}
}
「類/ englishman.ts」
import Person from "person"
export default class Englishman extends Person {
constructor(name: string){
this._language = "en_GB";
super(name);
}
}
「main.ts」
import * as $ from "jquery";
import Englishman from "classes/englishman";
let tom: Person = new Englishman("Tom");
console.log(tom);
$("body").html(`<h1>TEST</h1>`);
錯誤:
source/main.ts(2,24):錯誤TS2307:無法找到模塊 'classes/englishman'。 source/main.ts(4,10):錯誤TS2304:找不到 name'Person'。 [13時53分43秒] 打字稿:2個語義錯誤
完美!添加'。/'工作。我不知道爲什麼這應該是必要的,因爲我認爲從當前目錄開始是一個除非我們以'/'開頭......奇怪。 –