多看下生成的JS,从而看看处理的逻辑(使用不同的ES标准进行编译)
几个迁移的案例
https://developers.google.com/web/updates/2021/01/puppeteer-typescript
ROI
- 团队迁移成本
(开发思维,开发生态,项目处理,接口及声明文件的维护)
redaxios
https://www.tslang.cn/docs/handbook/type-checking-javascript-files.html
https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript
使用JSDoc注解
1 | // https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html |
推荐相关文档:
https://zhuanlan.zhihu.com/p/40322215
https://labs.thisdot.co/blog/your-first-vue-3-app-using-typescript
https://medium.com/vue-typescript/vue-3-with-typescript-setup-a-new-project-with-the-vue-cli-4ea806be7a91
推荐TS入门:
https://basarat.gitbook.io/typescript/getting-started
https://jkchao.github.io/typescript-book-chinese/typings/types.html#%E4%BD%BF%E7%94%A8-types
教程推荐
- 英文OK的还是官方文档
- 中文的话:
项目总结
接入的第三方插件
sentry
- sentry本身就有@sentry/types,被JavaScript 相关的 SDK依赖,所以没啥问题,安装之后,就支持了
- https://getsentry.github.io/sentry-javascript/
type vs interface
官方example
1 | // There are two main tools to declare the shape of an |
declare
- https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html
declare module ‘xxx’
- 声明一个全局模块
- 解决查找模块路径的问题
1
2
3
4
5
6
7
8
9
10# env.d.ts
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
} - 环境声明 - *.d.ts文件, 里面每个根级别的声明需要以declare作为前缀
当你安装TypeScript时,会顺带安装一个lib.d.ts声明文件。这个文件包含JavaScript运行时及DOM(Document Object Model,文档对象模型)中存在的各种常见的JavaScript环境声明。● 它自动包含在TypeScript项目的编译上下文中。● 它能让你快速开始书写经过类型检查的JavaScript代码。
tsconfig
- strictNullCheck 建议设置true,如果有需要都允许的地方,可以使用联合类型
sources
- https://drive.google.com/file/d/170oHzpLNeprUa-TMmOAnSU4caEFDSb3e/view
- https://github.com/mike-works/typescript-fundamentals/tree/v2#dependencies
why
用typescript的原因,是一种思维模式上面的减负;想应该想的,一些语言特性里面的遗留问题,不需要再想
1 | undefined == null // true |
https://github.com/lodash/lodash.git
注释
1 | TypeScript 的 3.7 版本引入了 -nocheck 注释,可以增加在 TypeScript 文件的头部来禁用语义检查。我们没有使用这个注释,因为它之前不支持.ts/.tsx 文件,但它也可以在迁移过程中成为一个很好的中间阶段助手。 |