Language/Typescript 4

[Typescript] Generics으로 Axios 깔끔하게 사용해보기

사이드 프로젝트를 하면서 여느때와 같이 Axios 인스턴스를 만들어서 사용하고 있다. 칸반 리팩토링을 하면서 Generics을 사용해 서버에서 만들어주는 응답값 인터페이스를 만들고, 각 api 함수를 선언시 Generics에 들어갈 타입을 지정해주도록 수정해서 pr을 올렸었다. // apis/kanban.ts interface IResponse { success: boolean; error: any; data: T; } export const fetchKanbanList = async (): Promise => { const data: IResponse = await goHigerApi.get('/v1/applications/kanban'); return data; }; 첨엔 나름 괜찮은것같다고 생각했지..

Language/Typescript 2024.01.04

[Typescript] styled Components Typescript Definitions

https://styled-components.com/docs/api#typescript styled-components: API Reference API Reference of styled-components styled-components.com 1. Create a declarations file styled.d.ts 의 정의 파일을 만든다. styled.d.ts // import original module declarations import 'styled-components'; // and extend them! declare module 'styled-components' { export interface DefaultTheme { borderRadius: string; colors: { ma..

Language/Typescript 2023.01.07

[Typescript] Typescript Tutorial

1. Installation 1-1. 리액트 앱을 타입스크립트로 새로만들 때 npx create-react-app my-app --template typescript 1-2. 이미 만들어진 리액트 앱에 타입스크립트 추가할 때 npm install --save typescript @types/node @types/react @types/react-dom @types/jest 2.Definitely Typed styled-components, react-router-dom 등 js 기반의 라이브러리에게 typescript를 사용할 것이라고 알려줘야 한다. npm i --save-dev @types/패키지명 https://github.com/DefinitelyTyped/DefinitelyTyped GitHub..

Language/Typescript 2023.01.03