Indexable Type

Donghun Seol·2023년 3월 31일
0

타입스크립트에서 객체를 생성할때 유연한 킷값을 갖는 객체를 타이핑하기 위해 활용한다.

type KeyValueType = {
  [key: string]: string;
};

const makeObject = (key: string, value: string): KeyValueType => ({
  [key]: value,
});

console.log(makeObject('mykey', 'myval'));
console.log(makeObject('capital', 'seoul'));
profile
I'm going from failure to failure without losing enthusiasm

0개의 댓글