본문으로 건너뛰기
yceffort
PostsSeriesTagsAbout🧪 Research
EN

Tweaks

theme
accent palette
film grain
minimal mode
BACK TO INDEX
◆ ESSAY
--min
--year
KOoriginal

mailMail icongithubtwitter
yceffort
•
© 2026
•
https://yceffort.kr
BACK TO INDEX
◆ ESSAY

suppressImplicitAnyIndexErrors 옵션을 키기 전에

avatar
yceffort
2021-05-23 · 2분
2min
2021year
KOoriginal
typescript

타입스크립트를 배우고, 본격적으로 사용하면서 부딪히는 가장 최초의 어려움은 바로 이 에러가 아닐 까 싶다.

Element implicitly has an 'any' type because type '{}' has no index signature.
  • https://www.typescriptlang.org/tsconfig#suppressImplicitAnyIndexErrors
  • https://www.typescriptlang.org/tsconfig#noImplicitAny

보통 이런 에러는 아래와 같은 코드에서 나타난다.

for (const [key, value] of Object.entries(obj)) {
  ///...
}

Object.entries 는 아마도 다음과 같이 타이핑이 되어 있을 것이다.

entries(o: {}): [string, any][];
const test = {a: 'a', b: 'b', c: 'c'}
for (const [k, v] of Object.entries(test)) {
  const value = test[k] // Element implicitly has an 'any' type because index expression is not of type 'number'.ts(7015)
}

k 객체의 키로 v를 추정할 수 없기 때문에 발생하는 문제다.

이럴 때는 아래와 같이 작업해보자.

방법 1.

type testKey = 'a' | 'b' | 'c'

const test: {[key in testKey]: string} = {a: 'a', b: 'b', c: 'c'}
for (const [k, v] of Object.entries(test)) {
  const value = test[k as testKey]
  console.log(k === v)
}

object의 key의 타입을 추론한다음, 이를 설정하는 방법이다.

방법 2.

function entries<O extends Object>(obj: O): Array<[keyof O, any]> {
  return Object.entries(obj) as Array<[keyof O, any]>
}

for (const [k, v] of entries(test)) {
  const value = test[k]
  console.log(k === v)
}

느슨하게 타이핑되어 있는 Object.entries를 강력하게 test 객체의 형태에 맞 맞춰 타이핑한다.

관련 글

  • #typescript#oxc#eslint

    typescript@7을 설치하면 벌어지는 일들: 블로그 모노레포 마이그레이션 기록

    pnpm lint가 12분 32초 걸리던 모노레포에 typescript 7.0.2를 넣어봤다. 타입체크는 조용히 지나갔는데 next build가 깨졌고, lint는 크래시했다. eslint와 prettier를 oxlint와 oxfmt로 갈아탄 하루의 연쇄 반응과 전후 실측 기록. 미리 말해두면, 빌드는 빨라지지 않았다.

    2026-08-10·17분
  • #typescript#backend

    Effect 시스템 심층 분석: 모나드에서 Algebraic Effects까지, 그리고 Effect-TS의 선택

    Effect-TS가 대체 뭔데 다들 난리인지 직접 파헤쳐봤다.

    2026-02-20·41분
  • #typescript

    TypeScript에서 switch문의 모든 케이스를 빠짐없이 처리했는지 검사하는 방법

    never 타입을 활용한 exhaustive check 패턴

    2026-01-17·13분
  • #react#typescript

    useEvent에서 useEffectEvent까지: React의 이벤트 핸들러 안정화 여정

    3년 전 RFC가 드디어 빛을 보다

    2025-12-15·24분

새 글을 놓치고 싶지 않으시다면 RSS로 구독해 주세요.

RSS 구독 →

yceffort — 프론트엔드 엔지니어입니다. 발표·기술 자문·기고 문의는 이곳에서 받고 있습니다.

← Back to the blogIssue on GitHub →