• Jack Q
    2024-06-20 来自广东
    作业: 惰性求值类型 type Trans<T> = T; // 1.字符串模版 type Templete = `${string}_${string}`;// 包含定界符 type TempleteT = Trans<Templete>; // 2.keyof T type Obj = { a: 1; b: string; c: [number, number] }; type ObjT = Trans<Obj>; // 3.typeof class class C {} type CT = Trans<typeof C> // let v = { a: 'a', c: C } // function F() {} // type VT = Trans<typeof v> // type FT = Trans<typeof F> // 4.包含剩余元素语法的元组 type RestTuple = [number, boolean, ...boolean[]]; type RestTupleT = Trans<RestTuple>; // 5.mapping 中 index 部分存在惰性求值 type Mapping = { [k in Templete]: any } type MappingT = Trans<Mapping> // 6.结构类型交叉 type Intersect = Obj & { e: boolean } type IntersectT = Trans<Intersect> // 7.联合类型 type Union = Obj | keyof Obj | [number, number]; type UnionT = Trans<Union> // 8.未实力化的类型 class GenericA<T> { s!: [...number[], T]; }; type TAT = Trans<typeof GenericA.prototype>; // 9.表达带范型参数的 类型别名 type GenericF = <T>() => T extends boolean ? true : false; type TFT = Trans<GenericF>;
    展开

    作者回复: 赞的。++

    
    