ts中存在兩種聲明空間:類型聲明空間和變量聲明空間
類型聲明
interface Bar {}
type Bas = {};
let bar: Bar;
let bas: Bas;
// 但是不能當作變量使用
interface Bar {}
const bar = Bar; // Error: "cannot find name 'Bar'"
變量聲明
class Foo {}
// 當作類型使用
let foo: Foo;
// 當作變量使用
const someVar = Foo;
const someOtherVar = 123;
// 這是變量聲明,不能用做類型注釋
const foo = 123;
let bar: foo; // ERROR: "cannot find name 'foo'"
常用網站:
SegmentFault |
GitHub |
掘金社群