인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

honux's profile image
honux

asked

TypeScript Introduction - From Basics to Practice

An interface that defines the indexing method.

이 방식을 뭐라고 부르나요? 전화번호부에서 객체 선언에도 사용을 했더라구요.

Resolved

Written on

·

166

8

뒤쪽 전화번호부 프로젝트 보면 오브젝트의 키 정의에도 사용을 했더라구요. 처음에 본 것 같기도 하면서 생소하기도 했는데 인덱싱 방식 정의랑 같은 거였네요.

 interface PhoneNumberDictionary {
    [phone: string]: {
      num: number;
    };
  }

es6typescriptjavascript

Answer 2

6

captain님의 프로필 이미지
captain
Instructor

오 넹 맞아요 교수님. 객체에 어떤 키가 들어올지 모를 때 저렇게 인덱싱을 정의할 수 있습니다 :) 보통 객체 속성을 접근할 때 타입 오류가 나면 위와 같은 방식으로 해결하시면 돼요. 아 이거 제가 강의에서 자세히 설명을 안했나보네요! 

5

honux님의 프로필 이미지
honux
Questioner

 Indexable types have an index signature that describes the types we can use to index into the object, along with the corresponding return types when indexing. 이라고 가이드북에 있는 내용을 찾았습니다. Indexable types 이라고 하는거군요. 

honux's profile image
honux

asked

Ask a question