I have been experimenting with computed properties in TypeScript, but I've encountered a specific issue:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'User1'.
No index signature with a parameter of type 'string' was found on type 'User1'
Below is the code snippet causing the error:
type User1 = {
name: string;
age: number;
address: string;
};
const user1: User1 = {
name: "user1",
age: 23,
address: "address",
};
let checkParameter: string | number = "name";
console.log(user1[checkParameter]); //error occurring here
checkParameter = "age";
console.log(user1[checkParameter]); //error occurring here
checkParameter = "address";
console.log(user1[checkParameter]); //error occurring here
The value of checkParameter is determined randomly at runtime.
I'm aiming for smooth execution without any errors.