I don't know what exactly to call this problem but this is my case.
I want defaultValue to automatically get type based on id value.
type User = {
name: string;
age: number;
};
type PropConfig<T, K extends keyof T> = {
id: K;
label: string;
defaultValue: T[K];
};
const config: PropConfig<User, 'age'> = {
id: 'age',
label: 'Age',
defaultValue: 18,
};
This is what I want:
type PropConfig<T, K = keyof T> = {
id: K;
label: string;
defaultValue: T[K]; // Error here
};
const config: PropConfig<User> = {
id: 'age',
label: 'Age',
defaultValue: 18,
};
Can someone help me?