-
[TypeScript] 매번 다르게 전달되는 JSON 에 대해 타입 정의하기프로그래밍 언어/JavaScript & TypeScript 2022. 9. 17. 17:18
interface Person { [key: string]: string | number; name: string; age: number; userIdentity: { [key: string]: string }; } const p1: Person = { name: 'Tom', country: 'Chile', age: 30, userIdentity: {userName: 'Ping9', region: 'us-east-1'}};
Reference
What does {[key: string]: string} mean in TypeScript | bobbyhadz
The `{[key: string]: string}` syntax is an index signature in TypeScript and is used when we don't know all the names of a type's properties ahead of time, but we know the shape of the values. The index signature specifies a key and value of type `string`.
bobbyhadz.com
728x90'프로그래밍 언어 > JavaScript & TypeScript' 카테고리의 다른 글
[JavaScript] Strict equality (===) 와 equality (==) (0) 2022.09.17 [JavaScript] JS ES6 에 추가된 기능 및 문법 정리 (0) 2021.11.09 [JavaScript] JavaScript 로 할 수 있는일 (0) 2021.08.24