typescript 类型练习之重新构造

type MapType = {
    [
        Key in keyof T 
            as `${Key & string}hhh${Key & number}${Key & string}`
    ]: [T[Key], T[Key], T[Key]]
}

type res = MapType<{a: 1, b: 2, c: 3}>;

type obj = {
    readonly name: string;
    age?: number;
    gender: boolean
}

type Mapping = {
    [Key in keyof Obj]: Obj[Key]
}

type res2 = Mapping<{name: 'sss', gender: 1, ss: '3'}>

type UppercaseKey = {
    [Key in keyof Obj as Uppercase]: Obj[Key]
}

type res3 = UppercaseKey<{name: '333'}>

type UppercasKey> = {
    [Key in keyof Obj as Uppercase]: Obj[Key]
}

type res4 = UppercasKey<{age: true}>

type ToPartial = {
    [Key in keyof T]?: T[Key]
}

type res5 = ToPartial<{
    name: string;
    age: number;
}>

type ToMutable = {
    -readonly [Key in keyof T]: T[Key]
}

type res6 = ToMutable<{
    readonly name: string;
    age: number;
}>

type ToRequired = {
    [Key in keyof T]-?: T[Key]
}

type res7 = ToRequired<{
    name?: string;
    age: number;
}>

type FilterByValueType, ValueType> = {
    [Key in keyof Obj  as ValueType extends Obj[Key] ? Key : never] : Obj[Key]
}

type res8 = FilterByValueType<{num: string, age: number}, string>

你可能感兴趣的:(typescript 类型练习之重新构造)