type Flip<T extends Record<string, string | number | boolean>> = {
[P in keyof T as `${T[P]}`]: P
}
Solution by devshinthant #35261
type Flip<T extends Record<string, string | number | boolean>> = {
[P in keyof T as `${T[P]}`]: P
}
Solution by devshinthant #35071
// your answers
type Flip<T extends Record<string, string | number | boolean>> = {
[P in keyof T as `${T[P]}`]: P
}
Solution by Jayce-liang #34787
// your answers
type Flip<T> = {
[K in keyof T as `${T[K] & (string | number | boolean)}`]: K
}
Solution by gobielJonathan #34530
type Flip<T extends Record<string, number | string | boolean>> = {
[K in keyof T as `${T[K]}`] : K
}
Solution by ouzexi #34066
type Flip<T> = {
[K in keyof T as T[K] extends string | number | boolean ? `${T[K]}` : never]: K
}
Solution by kai-phan #32519
type Flip<T> = {
[P in keyof T as T[P]]: P
}
Solution by rkamely #32105
type Flip<T> = {
[K in keyof T as `${T[K]}`]: K
}
Solution by Zhen-code #31995
ๆ่ถฃ๏ผๅพ็ไบts็ๆจกๆฟๅญ็ฌฆไธฒ
type Flip<T extends Record<string, any>> = {
[P in keyof T as `${T[P]}`]: P;
};
Solution by sunsunmonkey #31540
type Flip<T extends Record<string, string | number | boolean>> = {
[P in keyof T as `${T[P]}`]: P
}
Solution by MyeonghoonNam #31054
type Flip<T extends Record<string, string | number | boolean>> = {
[K in keyof T as `${T[K]}`]: K
}
Solution by yang49519845 #30182
type ObjectKey<T extends object, K extends keyof T, V> = K extends keyof T ? T[K] extends V ? K : never : never
type Flip<T extends object> = {
[P in T[keyof T] as P extends string | number | symbol ? P : `${P}`]: ObjectKey<T, keyof T, P>
}
Solution by zhangqiangzgz #30175
type Flip<T> = {
[P in keyof T as T[P] extends string | boolean | number | bigint | null | undefined ? `${T[P]}`: never]: P
}
Solution by 8471919 #30102
type Flip<T> = {
[P in keyof T as T[P] extends string | number | symbol
? T[P]
: T[P] extends boolean | bigint | null | undefined
? `${T[P]}`
: never]: P;
};
Solution by DoGukKim #29168
type Flip<T extends Record<keyof any, any>> = {
[K in keyof T as T[K] extends number | symbol
? T[K]
: `${T[K]}` extends `${infer Key}`
? Key
: never]: K;
};
Solution by DoubleWoodLin #28721
type Fibonacci<
T extends number,
R extends any[] = [[""]],
C extends any[] = [""]
> = C["length"] extends T
? R extends [...infer F, infer RES extends any[]]
? RES["length"]
: never
: Fibonacci<
T,
R extends [infer D extends any[], infer M extends any[]]
? [M, [...D, ...M]]
: [["1"], ["1"]],
[...C, ""]
>
Solution by duanbx #28633
// your answers
type Flip<T extends {}> = { [K in keyof T as `${T[K]}`]: K }
Solution by AAA611 #27897
// your answers
type Flip<T extends {[key: string|number]: string|number|boolean}> = {
[K in keyof T as T[K] extends string|number ? T[K] : `${T[K]}`]: K
}
Solution by Take0518 #27801
type Flip<T> = T extends {[P in any]: any} ? {[K in keyof T as `${T[K]}`]: K} : T
Solution by HenrryShaw #27781
type Flip<T extends Record<PropertyKey, string | number | boolean>> = {
[K in keyof T as `${T[K]}`]: K
}
Solution by jjswifty #27650
type Flip<T extends { [key: string]: any }> = {
[key in keyof T as `${T[key]}`]: key
}
Solution by jiechliu #27504
type Keys = string | boolean | number | undefined | null | bigint
type Flip<T extends Record<PropertyKey, Keys>> = {
[K in keyof T as `${T[K]}`]: K
}
Solution by RainbowIsPerfect #27424
type Flip<T extends Record<PropertyKey, any>> = {
[K in keyof T as T[K] extends PropertyKey
? T[K]
: `${T[K]}`
]: K;
};
Solution by Azoraqua #27261
// your answers
type Flip<T extends { [key: PropertyKey]: any }> = {
[key in keyof T as T[key] extends PropertyKey ? T[key] : `${T[key]}`]: key
};
Solution by CheolMinBae #27036
type Flip<T extends Record<string, any>> = { [K in keyof T as `${T[K]}`]: K }
Solution by smileboyi #26983
type Flip<T extends Record<string, string | number | boolean>> = {
[K in keyof T as `${T[K]}`]: K;
};
Solution by ryuji-1to #26929
// type Flip<T extends {[key: string | number | symbol] : any }> = {[K in keyof T as T[K] ] : K } // true: 'bool'
type Flip<T extends {[key: string | number | symbol] : any }> = {[K in keyof T as `${T[K]}` ] : K }
Solution by jsujeong #26925
type GetValues<T> = T extends { [P in keyof T]: infer R } ? R : never;
type GetKeyOfValue<T, U> = keyof T extends infer R extends keyof T
? R extends string | number | symbol
? [T[R]] extends [U]
? R
: never
: never
: never;
type Flip<T> = GetValues<T> extends infer Value extends string | number | symbol
? { [P in Value]: GetKeyOfValue<T, P> }
: never;
Solution by rldnd #26867
type Flip<T extends Record<PropertyKey, any>>
= { [Key in keyof T as T[Key] extends PropertyKey ? T[Key] : `${T[Key]}`] : Key }
Solution by tokyo9pm #26731
type Flip<T extends Record<PropertyKey, any>> = {
[K in keyof T as ${T[K]}
]: K
}
Solution by HaoxueAllen #26557