Typescript
-
Property 'env' does not exist on type 'ImportMeta' 해결 (feat. Vite)Typescript 2023. 12. 21. 11:11
해당 오류는 env의 속성을 인식하지 못해서 발생하는 에러이다. Vite + TS 환경에서 환경 변수 사용을 위한 세팅을 해보자. 1. .env 파일을 프로젝트 루트에 생성 후 VITE_로 시작하는 변수에 값을 할당한다. VITE_SERVER_URL = https://test.app 2. env.d.ts 파일을 프로젝트 루트에 생성 후 환경 변수의 타입을 선언한다. interface ImportMeta { env: { VITE_SERVER_URL: string; }; } 3. tsconfig.json compilerOptions에 옵션을 추가한다. "types": ["vite/client"], 4. vite.config.ts import { defineConfig, loadEnv } from 'vite'..
-
[TS] 이벤트 타입 익히기 (계속 추가)Typescript 2023. 6. 20. 23:12
자주 쓰는 이벤트 타입 1) mouse event e:React.MouseEvent 2) input change event e:React.ChangeEvent 3) form submit event e: React.FormEvent 4) submit 후 name으로 값을 가져오기 (e: React.FormEvent) => { e.currentTarget.elements.namedItem('title') as HTMLInputElement; }; Error 1) 'EventTarget' 형식에 'className' 속성이 없습니다. const handleDot = (e: React.MouseEvent) => { const target = e.target as HTMLLIElement; target.class..
-
[TS] 무한스크롤 뉴스 뷰어 구현Typescript 2023. 6. 10. 00:58
타입스크립트를 익히기 위해서 프로젝트를 진행했는데, 타입스크립트를 사용했다고 하기엔 민망할 정도로 타입 선언이 없다,,,, https://newsapi.org/ News API – Search News and Blog Articles on the Web “Ascender AI has a mission to apply AI to the media, and NewsAPI is one of our most valuable resources. Ascender is redefining how users interact with complex information, and the NewsAPI feed is an essential showcase for our technologies.” Braddock Ga new..