I am encountering an issue while trying to implement this. The error message I'm getting is: "Type '{ [x: string]: boolean; }' is not assignable to type 'NextType'. Any ideas on how to resolve it?
type A = {
a: string
}
type B = {
a: boolean
};
type NextType<T extends object> = {
[K in keyof T]: T[keyof T] extends string ? boolean : string
}
const a: A = {
a: 'a',
}
function mapObjectStringPropToBoolean<T extends object>(
key: keyof T,
payload: T
): NextType<T> {
const value = payload[key];
return {
[key]: Boolean(value)
} // This works as NextType<T>!
}
let result: B = mapObjectStringPropToBoolean('a', a);