源注解代码 🔗 1 2 3 4 5 6 7 8 9 { readonly [K in keyof Defaults as K extends keyof T ? K : never]-?: K extends keyof T ? Defaults[K] extends undefined ? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]> : NotUndefined<T[K]> : never } 解读 🔗 索引签名和可选性: readonly [K in keyof Defaults as ...] -?: readonly: 表示
typescript 装饰器 🔗 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 declare type MethodDecorator = <T>( target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T> ) => TypedPropertyDescriptor<T> | void type VoidFn = ((...args: any[]) => void) | ((...args: any[]) => Promise<void>) export const Performance =
babel 和 tsc 编译typescript异同点 🔗总结 🔗 babel 和 tsc 的编译流程大同小异,都有把源码转换成 AST 的 Parser,都会做语义分析(作用域分析)和 AST 的 t
模式提取 🔗推导值类型 🔗 1 2 3 type p = Promise<"hello">; type MyGetValueResult<P> = P extends Promise<infer S> ? S : never; type pr = MyGetValueResult<p>; 推导数组元素 🔗 1 2 3 4 5 6 7 8 9 10 11 12 13 // First type f = [1, 2, 3]; type MyGetFirst<P extends unknown[]> = P extends [infer F,
Partial 🔗可选类型, 把原本必选的参数都改成可选参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 interface Crew { age: number; name: string; } const Jerry:Crew = { age: 10, name: 'jack' }; type AnonymousPeople = Partial<Crew>; const tom: AnonymousPeople = { name: 'Tom' }; keyof 🔗ke