본문 바로가기
IT/TypeScript

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ name: string; age: number; }'.

by 골든크랩 2022. 10. 28.
728x90
반응형

이 무슨 귀신 씨나락 까묵는 소린가 싶어 구글 검색을 했고,

아래 글을 발견함.  읽어볼것.

 

아래 코드는 유용한 기능 같다.

type EventType = "mouseout" | "mouseover" | "click"
function handleEvent(event: EventType) {}
handleEvent("click")
handleEvent("hover") // compile error: Argument of type '"hover"' is not assignable to parameter of type 'EventType'.

 

https://soopdop.github.io/2020/12/01/index-signatures-in-typescript/

 

TypeScript에서 string key로 객체에 접근하기

TypeScript에서 string key로 객체에 접근하기

soopdop.github.io

 

728x90
반응형

댓글