I'm trying to dynamically change object property values based on the property type, e.g., replace all object string properties with "***". I keep getting Type '"***"' is not assignable to type 'T[keyof T]'
I've tried finding the correct way of doing this in Typescript GitHub repository but no luck.
I'm using the latest version of Typescript as of writing this "3.8.2".
Anyone knows what is the correct way of changing object property values when accessing properties dynamically?
Example:
interface IClassA {
name: string;
age: number;
}
const user: IClassA = {
name: "Jhon Doe",
age: 20
};
obfuscate(user);
export function obfuscate<T extends IClassA>(obj: T) {
for (const prop of Reflect.ownKeys(obj) as (keyof T)[]) {
if (typeof obj[prop] === "string") {
obj[prop] = "***";
}
}
}

keyof Tis saying that the value ofpropwill bestring,number, orSymbol, AKA:obj['number']and notobj['name'].