type MapType<T> = {
[
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<Obj> = {
[Key in keyof Obj]: Obj[Key]
}
type res2 = Mapping<{name: 'sss', gender: 1, ss: '3'}>
type UppercaseKey<Obj extends object> = {
[Key in keyof Obj as Uppercase<Key & string>]: Obj[Key]
}
type res3 = UppercaseKey<{name: '333'}>
type UppercasKey<Obj extends Record<string, boolean>> = {
[Key in keyof Obj as Uppercase<Key & string>]: Obj[Key]
}
type res4 = UppercasKey<{age: true}>
type ToPartial<T> = {
[Key in keyof T]?: T[Key]
}
type res5 = ToPartial<{
name: string;
age: number;
}>
type ToMutable<T> = {
-readonly [Key in keyof T]: T[Key]
}
type res6 = ToMutable<{
readonly name: string;
age: number;
}>
type ToRequired<T> = {
[Key in keyof T]-?: T[Key]
}
type res7 = ToRequired<{
name?: string;
age: number;
}>
type FilterByValueType<Obj extends Record<string, any>, ValueType> = {
[Key in keyof Obj as ValueType extends Obj[Key] ? Key : never] : Obj[Key]
}
type res8 = FilterByValueType<{num: string, age: number}, string>
网友评论