1当vscode 内置的typescript 和node下面的不一致的时候
如果两个版本不一样会出现不兼容的情况
2在TypeScript中,interface和type可以用来定义类型。它们的主要区别在于:
- interface只能声明对象类型,而type可以声明任何类型,包括基本类型、联合类型、元组类型等。
- interface支持扩展,通过“extends”关键字可以继承其他接口。而type不支持继承。
- interface可以定义函数类型,而type不能。
- 在类型检查时,interface在遇到错误时会提示出错位置在哪,而type给出的错误信息可能没有interface那么明确。
总的来说,如果需要定义一个对象类型,并且需要继承其他接口或者定义函数类型,那么就使用interface;如果需要定义其它类型,或者需要进行联合类型等操作,那么就使用type。
3 就是typeScript中 !的用法 跟 ?号的用法类似但是!用于判断null 和undefined
4vue3+ts报错:找不到模块“@/views/home/index.vue”或其相应的类型声明。
解决办法利用 TypeScript Vue Plugin (Volar)
新建env.d.ts
// declare module "@/views/home.vue" {
// import type { DefineComponent } from "vue";
// const component: DefineComponent<{}, {}, any>;
// export default component;
// }
5typescript 因为版本报错 for (let i = startIndex ?? 0; i < array.length; i++{SyntaxError:Unexpected token '?'
解决办法就是切换node.js 的版本库