随笔分类 - TypeScript
摘要:
我在打包时发现终端抛出了一个错误:'xxx' is declared but its value is never read. ps:项目是用vite搭建的vue3+ts项目 原因:ts检测到你声明了一个变量,但是从未使用,就会报错。 解决方案:注释掉该变量或者使用该变量,亦或者使用忽略检查代码,让
阅读全文

摘要:
我使用了.md文件作为路由文件来引用,在开发中能正常显示,打包的时候就报错了 // vite.config.ts import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import markdown fr
阅读全文

摘要:
新建一个页面,引入该页面路径,想用@符号代替../之类的操作时 // index.ts export default [ { path: '/', name: 'home', component: () => import("@/views/home.vue") } ] 报错:Cannot find
阅读全文

摘要:
TypeScript 编译器的配置文件,用于指定编译 TypeScript 代码时的编译选项和编译目标等信息。 通过修改该文件,可以定制 TypeScript 编译器的行为,例如指定编译目标、启用或禁用特定的语言特性、设置代码检查规则等。以下是一些常用的配置项及其作用: compilerOption
阅读全文

摘要:
在函数中添加了判断且包含了return,如: if (isTrial) { return alert("666"); } 那么ts就会报这个异常,这也不算错误,但从ts的严格模式来看,是要给定一个默认返回值才行。 解决方案: if (isTrial) { return alert("666"); }
阅读全文

摘要:
今天晚上发现ts中无法用forEach遍历对象嵌套数组的数据,比如typeof arr 为 object,就只能用for in 或者Object.entries 再或者Object.keys。 我这里用的是for in: useEffect(() => { if (value) { const ar
阅读全文

摘要:
PromiseResponsePaginateResult: 简介:一个TypeScript 的类型,用于处理异步操作返回的分页结果,类似于promise,包含分页信息 属性: data:数据源 total:数据量的总数 limit:每页数据量 page:当前页码 pages:总页数
阅读全文

摘要:
在 TypeScript 中,可以使用以下方式来定义数组: 使用类型加上方括号 [] 表示数组的类型: let numbers: number[] = [1, 2, 3, 4, 5]; let names: string[] = ["Alice", "Bob", "Charlie"]; 使用泛型 A
阅读全文

摘要:如题,react+taro+ts小程序开发,在给一个变量设值的时候报错,如: 初始化变量 const [isChecked, setCheck] = useState([]); 设值 setCheck([123]); 原因:默认 [] 会被ts 推导成never[]类型。 解决方案:把useStat
阅读全文