Can somebody explain me this case, I have some types and definitions:
type Registro = {
id: number;
registro: string;
nombre: string;
};
const registros: Registro[] = [
{
id: 0,
registro: '4324',
nombre: 'Ben'
},
{
id: 1,
registro: '232',
nombre: 'Jill'
}
];
If I use a literal string 'id', TS compiles fine
const a = registros[0]['id']; //OK
If I use a constant straight from a literal, TS also compiles fine
const key1 = 'id';
const c = registros[0][key1]; //OK
If I use a variable as a key even though it says its a :string , it will give an error
let key2 = 'id';
const d = registros[0][key2];
//Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Registro'.
//No index signature with a parameter of type 'string' was found on type 'Registro'.ts(7053)
If I use a constant as a key coming from a variable. and also it says its a :string , it will also error
let key3 = 'id';
const key4 = key3;
const e = registros[0][key4];
//Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Registro'.
//No index signature with a parameter of type 'string' was found on type 'Registro'.
What is the problem?