next.js 添加 ts的支持

3 min read

启动 TypeScrip!

第一步就是安装 TypeScript。

yarn global add typescript

创建 tsconfig.json

然后我们运行 tsc \--init,得到 tsconfig.json,这是 TypeScript 的配置文件。

接下来安装类型声明文件,然后重启项目。

yarn add --dev typescript @types/react @types/node
yarn dev

然后我们将文件名 index.js 改为 index.tsx。

使用 next-images

next-env.d.ts 文件中添加 next-images 类型的引用就好啦。

/// <reference types="next-images" />