Tuple to Object

이영광·2021년 12월 15일
0

타입챌린지's

목록 보기
2/2

Give an array, transform into an object type and the key/value must in the given array.

For example

const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const

type result = TupleToObject<typeof tuple> // expected { tesla: 'tesla', 'model 3': 'model 3', 'model X': 'model X', 'model Y': 'model Y'}

배열로 가지고오는 것을 객체 타입에 키와 값으로서 배열의 인덱스를 가져오면된다

  • result

    type TupleToObject<T extends string[](any로해도되는데 우선 스트링타입으로하고있어서 명확하게)>
     = { 
    k in T[number] : K
    }
    
profile
《REACT》《JAVASCRIPT 》 만지고있어욤

0개의 댓글

관련 채용 정보