接口interface

就相当于一个结构体,语法:

1
2
3
4
5
6
7
8
9
10
// 定义
export interface cry{
time: Date,
name: string,
}
//导入
import {type cry} from "@/types";
let crys : Array<cry> = [
{2025-11-10T08:00:00Z, "devil may cry"}
]

配置@符号

通常将@符表示以src为根路径,比如@/types/就表示src/types,但是这个符号并非默认,需要手动配置。打开tsconfig.json,添加:

1
2
3
4
5
6
7
8
{
"CompilerOptions": {
"baseUrl" : ".",
"paths":{
"@/*": ["src/*"]
}
}
}

为什么”@/*”后面映射的是括号?gpt说里面可以包含多个路径,按照数组的顺序,找不到就找下一个。