IT/TypeScript

확장 interface -extends를 사용 type - &를 사용 interface Student { major: string studentId: number } const mike: Student = { major: 'computer', studentId: 202212011 } type Student = { major: string studentId: number } const mike: Student = { major: 'computer', studentId: 202212011 } 선언적 확장 interface에서는 새로운 속성을 추가하기 위해 같은 이름을 선언할 수 있지만, type은 선언적 확장이 불가능하다. interface Student { major: string studentId: nu..
일단 기본적으로 타입을 추가해줘야 한다! 이건 당연하다! 1. import 할 때 이미지 파일 관련 에러 Cannot find modules '../..' or its corresponding type declarations. ts(2307) 라고 수많은 에러가 발생했다. 그럼 해결해 보자! src파일 아래에 images.d.ts파일을 생성한다. (index.d.ts로 파일명을 하면 index.ts파일로 인식하기 때문에 다른 이름으로 해주기) 필요한 확장자를 아래와 같이 추가해준다. declare module "*.png"; declare module "*.jpg"; tsconfig.json에 compilerOptions:{} 안에 추가해준다. "typeRoots": ["./src/@types"] 저장을..
새로운 타입 스크립트를 이용한 리액트 프로젝트를 시작했다. 타입 스크립트를 복습할 겸 기존의 JavaScript로 만들었던 프로젝트를 TypeScript로 변경해보기로 했다. TypeScript를 설치한다. yarn add typescript @types/node @types/react @types/react-dom @types/jest // 또는 npm install typescript @types/node @types/react @types/react-dom @types/jest 그다음 yarn install // 또는 npm install tsconfig.json파일이 생성된다. (혹은 생성되지 않았다면 tsconfig.json을 최상단에 추가해준다.) 아래 소스를 tsconfig.json에 추가해..
솔B
'IT/TypeScript' 카테고리의 글 목록