I've got this complex object
const classes = {
Barbarian: {
armorAndWeoponProficianies: [
'lightAmour',
'mediumArmour',
'Sheilds',
'simpleWeopons',
'martialWeopons',
],
class: 'Barbarian',
description:
'A fierce warrior of primitive background who can enter a battle rage',
hitDie: '1d12',
primaryAbility: 'STR',
savingThrowProficianies: ['STR', 'CON'],
},
Bard: {
armorAndWeoponProficianies: [
'lightArmor',
'simpleWeapons',
'handCrossbows',
'longswords',
'rapiers',
'shortswords',
],
class: 'Bard',
description:
'An inspiring magician whose power echoes the music of creation',
hitDie: '1d8',
primaryAbility: 'CHA',
savingThrowProficianies: ['DEX', 'CHA'],
},
}
and here I want to use the argument classType as a key but TypeScript doesnt like it
const hitPointGenerator = (classType: string) => {
const selectedClass = classes[classType].hitDie;
// ^ Error
console.log(selectedClass)
};
and the error i get is
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ Barbarian: { armorAndWeoponProficianies: string[]; class: string; description: string; hitDie: string; primaryAbility: string; savingThrowProficianies: string[]; }; Bard: { armorAndWeoponProficianies: string[]; ... 4 more ...; savingThrowProficianies: string[]; }; ... 9 more ...; Wizzard: { ...; }; }'.
No index signature with a parameter of type 'string' was found on type '{ Barbarian: { armorAndWeoponProficianies: string[]; class: string; description: string; hitDie: string; primaryAbility: string; savingThrowProficianies: string[]; }; Bard: { armorAndWeoponProficianies: string[]; ... 4 more ...; savingThrowProficianies: string[]; }; ... 9 more ...; Wizzard: { ...; }; }'.ts(7053)