枚举
export enum DIRECTIONS = {
UP = 1,
RIGHT = 2,
DOWN = 3,
LEFT = 4
}
类型别名和接口
// 类型别名
type Animal = {
type: string;
};
type Dog = Animal & {
bark: Function;
};
const dog: Dog = {
type: "dog",
bark: () => {},
};
// 接口
interface Animal {
type: string;
}
interface Dog extends Animal {
bark: Function;
}
const a: Dog = {
type: 'dog',
bark: () => {
}
}
泛型
const a: Array<string> = ['a', 'b'];
function get<T>(url: string): Promise<T> {
return fetch(url, {
method: "get",
headers: new Headers({
Accept: "application/json",
}),
}).then((response) => response.json());
}