随笔分类 - typeScript
摘要:这样做的目的是避免循环引用,编写多余的类型文件 //global.d.ts import type { A } from "./a"; import type { B } from "./b"; declare global { var a: A; var b: B; } //index.ts im
阅读全文
摘要:// 从 DataView 类型中取出key type get_set = keyof Omit<DataView, "buffer" | "byteLength" | "byteOffset">; type FilterNotStartingWith<Set, Needle extends str
阅读全文
摘要:在创建单例时,你可能会偷懒创建下面这样的代码 class A { static ins: A; arr = []; constructor() { return (A.ins ??= this); } } 上面的代码能创建单例,但是你却发现编译后的es6代码却是这鸟样 class A { const
阅读全文
摘要:interface Type<T> extends Function { new (...args: any[]): T; } class Data { name = "ajanuw"; echo() {} get info() { return {}; } } function cls<T>(va
阅读全文
摘要:interface IMessage { (value: any): void; success(): void; error(): void; version: string; } const Message: IMessage = function Message(value: any) { c
阅读全文
摘要:class User { constructor(public readonly name: string, public readonly value: Function) {} } class Data { values: any[] = []; register(name: string, v
阅读全文
摘要:```tstype Event = { name: string; dateCreated: string; type: string;}// errortype UserEvent extends Event = { UserId: string; }// 交集类型type UserEvent = Event & {UserId: string}```
阅读全文
摘要:传递参数 const cats = { "Coding Cat": "https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif", "Compiling Cat": "https://media.giphy.com/media/mlvseq9yvZh
阅读全文
摘要:```ts readonly name = "xxx"; updateValueAndValidity(): void { // this.name = 'a'; (this as { name: string }).name = "a"; } ```
阅读全文
摘要:interface SquareConfig { color?: string; width?: number; [propName: string]: any; } function asd(opt: SquareConfig): any { } asd({color: 'red', width:
阅读全文
摘要:文档http://es6.ruanyifeng.com/#docs/decorator ts文档 https://www.tslang.cn/docs/handbook/decorators.html#class-decorators 当多个装饰器应用于一个声明上,从上至下调用,从下而上执行 fun
阅读全文
摘要:安装依赖 λ yarn add typescript @types/node concurrently nodemon wait-on -D 初始化一个 tsconfig.json λ ./node_modules/.bin/tsc --init 编写 tsconfig.json { "compil
阅读全文