When I iterate over keys in TypeScript the variable is being assigned the type of string instead of type keyof object that I enumerate.
Example:
class Files {
patches?: Data;
website?: Data;
github?: Data;
}
const files: Files = {};
for (const file in Files.prototype) {
if (files[file]) {
console.log(files[file])
}
}
Error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Files'. No index signature with a parameter of type 'string' was found on type 'Files'.
How can I solve this?
keyoftype assertion.