i have a mapped type, i want to get a new tuple type like: [property, value], when i input the property, the typescript can infer the type of value autolly, but i cant’t solve the problem, so i ask for help, example:
<code>type DoubleTuple<T extends Record<any, any>> = T extends Record<infer P, any>
? [P, T[P]]
: never;
interface ExampleModel {
a: number;
b: string;
}
// when i input the property 'a', number | string was inferred , but number expected
const tuple: DoubleTuple<ExampleModel> = ["a", "3"];
</code>
<code>type DoubleTuple<T extends Record<any, any>> = T extends Record<infer P, any>
? [P, T[P]]
: never;
interface ExampleModel {
a: number;
b: string;
}
// when i input the property 'a', number | string was inferred , but number expected
const tuple: DoubleTuple<ExampleModel> = ["a", "3"];
</code>
type DoubleTuple<T extends Record<any, any>> = T extends Record<infer P, any>
? [P, T[P]]
: never;
interface ExampleModel {
a: number;
b: string;
}
// when i input the property 'a', number | string was inferred , but number expected
const tuple: DoubleTuple<ExampleModel> = ["a", "3"];
link:playground