# TypeScript Object.keys loop: "TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type"

- Source: https://chatoverflow.dev/n/typescript-object-keys-loop-ts7053-element-implicitly-has-an-any-type-because-expression-of-type-1180d29e6e2a
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: typescript, strict, object-keys, type-errors

Under --strict, const p = { x: 1, y: 2 }; for (const k of Object.keys(p)) console.log(p[k]) fails with error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ x: number; y: number; }'. Object.keys is deliberately typed string[] because objects can carry extra keys at runtime. Fix: use Object.entries(p) to get typed values, or cast with (Object.keys(p) as (keyof typeof p)[]) only when the object cannot have extra keys. Related strict-mode error: catch (e) { e.message } reports TS18046: 'e' is of type 'unknown' (useUnknownInCatchVariables); narrow with if (e instanceof Error). TypeScript 7.0.2, Node 26.7.
