随笔分类 -  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 阅读全文
posted @ 2024-05-23 08:21 Ajanuw 阅读(38) 评论(0) 推荐(0)
摘要:// 从 DataView 类型中取出key type get_set = keyof Omit<DataView, "buffer" | "byteLength" | "byteOffset">; type FilterNotStartingWith<Set, Needle extends str 阅读全文
posted @ 2022-11-14 18:13 Ajanuw 阅读(331) 评论(0) 推荐(0)
摘要:在创建单例时,你可能会偷懒创建下面这样的代码 class A { static ins: A; arr = []; constructor() { return (A.ins ??= this); } } 上面的代码能创建单例,但是你却发现编译后的es6代码却是这鸟样 class A { const 阅读全文
posted @ 2021-09-13 20:21 Ajanuw 阅读(120) 评论(0) 推荐(0)
摘要:interface Type<T> extends Function { new (...args: any[]): T; } class Data { name = "ajanuw"; echo() {} get info() { return {}; } } function cls<T>(va 阅读全文
posted @ 2020-12-08 10:27 Ajanuw 阅读(3602) 评论(0) 推荐(0)
摘要:interface IMessage { (value: any): void; success(): void; error(): void; version: string; } const Message: IMessage = function Message(value: any) { c 阅读全文
posted @ 2020-12-08 09:54 Ajanuw 阅读(1153) 评论(0) 推荐(0)
摘要:class User { constructor(public readonly name: string, public readonly value: Function) {} } class Data { values: any[] = []; register(name: string, v 阅读全文
posted @ 2020-12-08 09:48 Ajanuw 阅读(818) 评论(0) 推荐(0)
摘要:"tslint rules" 阅读全文
posted @ 2020-02-10 16:47 Ajanuw 阅读(2720) 评论(0) 推荐(0)
摘要:```tstype Event = { name: string; dateCreated: string; type: string;}// errortype UserEvent extends Event = { UserId: string; }// 交集类型type UserEvent = Event & {UserId: string}``` 阅读全文
posted @ 2020-02-02 17:59 Ajanuw 阅读(633) 评论(0) 推荐(0)
摘要:传递参数 const cats = { "Coding Cat": "https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif", "Compiling Cat": "https://media.giphy.com/media/mlvseq9yvZh 阅读全文
posted @ 2020-01-31 13:58 Ajanuw 阅读(3589) 评论(0) 推荐(0)
摘要:```ts readonly name = "xxx"; updateValueAndValidity(): void { // this.name = 'a'; (this as { name: string }).name = "a"; } ``` 阅读全文
posted @ 2019-12-19 14:27 Ajanuw 阅读(1256) 评论(0) 推荐(0)
摘要:interface SquareConfig { color?: string; width?: number; [propName: string]: any; } function asd(opt: SquareConfig): any { } asd({color: 'red', width: 阅读全文
posted @ 2018-10-19 22:19 Ajanuw 阅读(488) 评论(0) 推荐(0)
摘要:文档http://es6.ruanyifeng.com/#docs/decorator ts文档 https://www.tslang.cn/docs/handbook/decorators.html#class-decorators 当多个装饰器应用于一个声明上,从上至下调用,从下而上执行 fun 阅读全文
posted @ 2018-04-24 22:20 Ajanuw 阅读(869) 评论(0) 推荐(1)
摘要:安装依赖 λ yarn add typescript @types/node concurrently nodemon wait-on -D 初始化一个 tsconfig.json λ ./node_modules/.bin/tsc --init 编写 tsconfig.json { "compil 阅读全文
posted @ 2018-04-24 20:29 Ajanuw 阅读(1513) 评论(0) 推荐(0)