Ts
TS - ts 项目中,在 Vite 中配置了路径别名还是提示模块未找到
光在 Vite 中配置还不行,启动项目之后运行不会报错,正常导入模块。 ```ts export default defineConfig(({ command, mode }) => { return { resolve: { lit:[alias: { "@root": path.resolve ......
TypeScript(TS)JavaScript(JS)中的所有循环方法
for循环: for (let i = 0; i < array.length; i++) { // 循环体 } for…of循环: for (const element of array) { // 循环体 } forEach方法: array.forEach((element) => { // ......
前端命令——编译文件ts scss sass 等
## 1. 安装 ```bash npm install -g typescript ``` ```bash tsc --initÏ ``` ## 2. 使用方法 ### 2.1、将ts文件转化为js ```bash tsc index.ts ``` 会自动生成对应的index.js文件 ### 2 ......
【算法】在vue3的ts代码中分组group聚合源数据列表
有一个IList<any>()对象列表, 示例数据为[{id:'1',fieldName:'field1',value:'1'},{id:'1',fieldName:'field2',value:'2'},{id:'2',fieldName:'field1',value:'1'},{id:'2',f ......
typeScript学习-TS类型-其他特殊类型-可变元组
typeScript学习 可变元组: let people: [string, number, string, string, string] = ["wangwu", 23, "地址", '13312341234', '备注'] // 当前三个数据固定格式,后面数据不确认格式时 用可变元组 // ......
typeScript学习-TS类型-对象类型-Array
typeScript学习 对象类型-Array 数组和数组元素只读 const account = [10, 40, 50, 60, 90] as const // account[0] = 100 // 错误 export { } ......
typeScript学习-TS类型-其他特殊类型-元组(tuple)
typeScript学习 元组(tuple): 满足以下3点的数组就是元组 (1)在定义时每个元素的类型都是确定 (2)元素值的数据类型必须是当前元素定义的类型 (3)元素值的个数必须和定义时个数相同 let salary: [string, number, number, number, numb ......
vue3+vite+ts项目初始化
### 创建项目 ``` # npm 6.x npm create vite@latest my-vue-app --template vue # npm 7+, extra double-dash is needed: npm create vite@latest my-vue-app -- -- ......
vue3+ts绘制二维码
界面展示 实现步骤 引入qrcode.vue npm i qrcode.vue 界面引入并使用 <template> <div> <el-row>二维码标签</el-row> <el-row :gutter="20"> <el-col :span="6"> <el-input v-model="co ......
ts中this的处理
ts函数中,直接使用this会报错: "this" 隐式具有类型 "any",因为它没有类型注释。 应该以参数形式声明this,以防抖函数为例 function debounce(fn: Function, time: number) { let timer: number return funct ......
typeScript学习-TS类型-null和undefined
typeScript学习 null 和 undefined undefined any unknown 可以接受 undefined let data: undefined = undefined let data2: any = undefined let data3: unknown = und ......
typeScript学习-TS类型-合成类型
typeScript学习 合成类型:联合类型, 交叉类型 联合类型: let str:srting | number = "abc" str=3 交叉类型: type Obj1 = {username:string} type Obj2 = {age:number} let obj:Obj1={us ......
typeScript学习-TS类型-字面量数据类型
typeScript学习 字面量数据类型: // type A = number | string // let a:A = "abc" // type num = number // let n:num = 3 type num = 1 | 2 | 3 let n:num = 2 // 错误情况 ......
typeScript学习-TS类型-其他特殊类型-never
typeScript学习 其他特殊类型: any, unknown, never, void, 元组(tuple), 可变元组 never: // dataFlowAnalysisWithNever 方法穷尽了 DataFlow 的所有可能类型。 // 使用 never 避免出现未来扩展新的类没有对 ......
typeScript学习-TS类型-其他特殊类型-any、unknown
typeScript学习 其他特殊类型: any, unknown, never, void, 元组(tuple), 可变元组 any 比较经典的应用场景: 1、自定义守卫 2、需要进行 as any 类型断言的场景 unknown 一般用作函数参数: 用来接收任意类型的变量实参,但在函数内部只用于 ......
typeScript学习-TS类型-枚举
typeScript学习 枚举:enum 枚举的定义:用来存放一组固定的常量的序列。 枚举带来的好处: 1、有默认值和可以自增值,节省编码时间 2、语义更清晰,可读性增强, 因为枚举是一种值类型的数据类型,方法参数可以明确参数类型为枚举类型 enum WeekEnd { Monday = "myMo ......
typeScript学习-TS类型-接口
typeScript学习 接口: 定义:另一种定义对象类型的类型 接口应用场景: 1、一些第三方包或者框架底层源码中有大量的接口类型 2、提供方法的对象类型的参数时使用 3、为多个同类别的类提供统一的方法和属性声明 如何定义接口: 继承接口: 新的接口只是在原来接口集成之上增加了一些属性或方法,这是 ......
TS函数重载
1.函数重载的目的 重载允许一个函数接受不同数量或类型的参数时,作出不同的处理。 2.重载的实现 允许一个函数接受不同数量或类型的参数 我们重复定义了多次函数 reverse,前几次都是函数定义,最后一次是函数实现。在编辑器的代码提示中,可以正确的看到前两个提示。 注意,TypeScript 会优先 ......
typeScript学习-TS类型
typeScript学习 常用的24中 TS 类型 基本类型: number, string, boolean, symbol, null, undefined 根类型: Object, {} Object:除了 null 和 undefined,其他类型都可以赋值给 Object 类型,简写{}。 ......
引入外部ts文件,修改外部ts参数
<template> <div class="home"> <div>调用外部js:{{addNum}}</div> <button @click="clickAdd">加</button> <div>改变外部js参数:{{count}}</div> <button @click="clickCha ......
uniapp+ts页面接收传参
<script setup lang="ts"> import { onLoad } from '@dcloudio/uni-app'; //接收传参 onLoad(options => { console.log(options ); }); </script> ......
ts执行文件报错
我重新安装了项目的 npm 包,执行 ts 文件报错: tsc src/index.ts node_modules/@types/node/globals.d.ts:72:13 - error TS2403: Subsequent variable declarations must have th ......
如何为你的 js 项目添加 ts 支持?
前一段时间为公司内的一个 JS 公共库,增加了一些 TypeScript 类型支持。在这里简答记录一下。  ## 安 ......
ts总结
> 原文地址 [juejin.cn](https://juejin.cn/post/7088304364078497800) 先来看看知识图,如果你对以下概念有盲区,那么这篇文章应该能很好的帮助到你~  1. 运行环境 node -v v18.17.0 npm -v 9.8. ......
ts中的泛型
在 TypeScript 中我们会使用泛型来对函数的相关类型进行约束 这里的函数 同时包含 class 的构造函数 因此 一个类的声明部分 也可以使用泛型 那么 什么是泛型? 如果通俗的理解泛型呐? ### 什么是泛型 **泛型 (Generics) 是指在定义函数 接口或类的时候 不预先指定具体的 ......
TS中的Type和Interface
> 学习内容来源于:https://www.youtube.com/watch?v=Idf0zh9f3qQ # Type 与 Interface的区别 1. 编写方式 ```ts type UserProps = { name: string; age: number; } interface Us ......
Angular:error TS2717: Subsequent property declarations must have the same type. Property 'contentRect' mu st be of type 'DOMRectReadOnly', but here has type 'DOMRectReadOnly'.
# 解决方案 在`tsconfig.json`的`compilerOptions`选项中添加如下内容`"skipLibCheck": true`。 如下图所示 ![image](https://img2023.cnblogs.com/blog/1795938/202307/1795938-20230 ......