2025年2月16日

mixins

摘要: // 对象的混入 type A = { name: string } type B = { age: number } const a9:A = { name: 'xiaobai' } const b9:B = { age: 15 } // 使用扩展运算符此时c9的类型推断 // { // name 阅读全文

posted @ 2025-02-16 17:34 ChoZ 阅读(1) 评论(0) 推荐(0) 编辑

declare module

摘要: // index.d.ts文件是描述该插件如何使用的说明,如果插件缺失该文件import时候会报错 import Axios from 'axios' // 不会报错,通过ctrl+点击会进去该index.d.ts文件 // express缺失index.d.ts直接import会报错 // 方法1 阅读全文

posted @ 2025-02-16 16:54 ChoZ 阅读(1) 评论(0) 推荐(0) 编辑

export

摘要: // import importA from './export' // 导入default可随意命名 // import { exportDemo } from './export' // 解构需要对应名字 // 可以使用as重命名 import { exportDemo as exportDem 阅读全文

posted @ 2025-02-16 15:29 ChoZ 阅读(1) 评论(0) 推荐(0) 编辑

namespace

摘要: // 基础使用导出、嵌套、合并、抽离、简化 namespace Test { let c = 6 export let b = 5 export const f = () => 1 // 嵌套的namespace也是要export,才能被外部引用 export namespace Test1 { e 阅读全文

posted @ 2025-02-16 00:51 ChoZ 阅读(2) 评论(0) 推荐(0) 编辑

2025年2月15日

泛型T keyof

摘要: // extends function A<T>(a:T,b:T) { // return a+b // 此时提示报错,因为不是任何类型都可以接受+,所以此时加号不安全 } // 通过泛型extends数字类型,number能够接收+,所以不会报错 function B<T extends numb 阅读全文

posted @ 2025-02-15 16:53 ChoZ 阅读(0) 评论(0) 推荐(0) 编辑

泛型T

摘要: // 泛型: 动态类型 // 用泛型整合下面2个函数为一个函数 function A(a:number,b:number):number[] { return [a,b] } function B(a:string,b:string):string[] { return [a,b] } // T是自 阅读全文

posted @ 2025-02-15 15:22 ChoZ 阅读(0) 评论(0) 推荐(0) 编辑

Symbol.iterator

摘要: // 生成器 // 生成器与迭代器使用方法一样 // function* gen() { // yield Promise.resolve('1') // 接同步代码异步代码都可以 // yield '2' // yield '3' // } // const man = gen() // done 阅读全文

posted @ 2025-02-15 01:56 ChoZ 阅读(4) 评论(0) 推荐(0) 编辑

Symbol

摘要: // symbol表示是唯一值,哪怕值一样,也不会相等 let a1:symbol = Symbol(1) let a2:symbol = Symbol(1) // console.log(a1 == a2); // false // Symbol.for是全局搜索传入的值,如果没有就创建一个,如果 阅读全文

posted @ 2025-02-15 01:22 ChoZ 阅读(3) 评论(0) 推荐(0) 编辑

2025年2月14日

nerve

摘要: // nerve类型代表不可能有这个类型,例如同时是string和number,会推断为nerve type a = string & number // 因为nerve是最底层的类型,前面有了number和void类型会自动忽略nerve类型 type b = number | void | ne 阅读全文

posted @ 2025-02-14 22:42 ChoZ 阅读(1) 评论(0) 推荐(0) 编辑

type

摘要: // ts自带类型推论,此时推论为string,要修改类型推论的话就自定义类型 let str = '456' // str = 456 // 赋值数字会报错 let str1 // 不定义会自动推论为any // type可以自定义名称,指定各种类型 type a = {} type b = [] 阅读全文

posted @ 2025-02-14 22:17 ChoZ 阅读(1) 评论(0) 推荐(0) 编辑

导航