js的原型链 prototype

title: js的原型链 prototype id: af4efcdffdb5e92e8f02c53e57924895 tags:

  • 知识点 date: 2000/01/01 00:00:00 updated: 2024/01/28 21:37:59 isPublic: true --#|[分隔]|#--

TS常用技巧

为window添加字段

// 给Window添加字段
declare interface Window {
  flag: string, // 给Window添加这个字段
  apple: string | number, // 给Window添加这个字段
}

为无声明文件的第三方包添加声明

// 可以给qs这个无类型的第三方包声明类型,声明成了any
declare module 'qs';

字符串数组生成type

把下面这个字符串数组,每一项的数组,转为 type 罗列出来:

const arr = ['apple', 'car', 'tree']
// 目标,根据上面的现有的数组,得到下面的类型
type Arr = 'apple' | 'car' | 'tree'

进行转换的方法:

把对象的key生成type

进行转换的方法:

Last updated

Was this helpful?