interface INewNumberextends number {} // 'number' only refers to a type, but is being used as a value here.
interface INewNumberextendsNumber {} // 这样写是可以的,但是不要忘记 1 instanceof Number === false
元组 不能使用 interface 声明元组
1 2 3 4 5 6 7 8 9 10 11
type Tuples = [number, number];
interface ITuples { 0: number; 1: number; }
[1, 2, 3] asTuples; // Conversion of type '[number, number, number]' to type 'Tuples' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Types of property 'length' are incompatible.
[1, 2, 3] asITuples;
不相关的合集 只有 type 可以做不相关合集
1
type SomeAnimal = { type: Dog } | { type: Cat };
且不能对 不相关集合不能使用 extends 关键字
1 2
interface ISomeAnimalextendsSomeAnimal {} // An interface can only extend an object type or intersection of object types with statically known members
每个作用域只能声明一次类型
1 2 3
type Once = { a: string }; type Once = { b: string }; // Duplicate identifier 'Once'