My goal is to achieve the following:
type UserDataProps<FieldName extends keyof DataShape, DataShape extends Record<string, any>> = {
id: string;
value: DataShape[FieldName];
}
const userDataBuilder = <FieldName extends keyof DataShape, DataShape extends Record<string, any>>(
name: FieldName,
data: DataShape,
): UserDataProps<FieldName, DataShape> => {
return {
id: name,
value: data[name],
}
}
However, I encounter an error indicating that 'name' is of type string | number | symbol
.
This seems odd since DataShape does extend Record<string, any>
, meaning its keys should be strings.
Is this behavior expected? If so, is there a way to resolve it?
Thank you :)