본문 바로가기

React & TypeScript/TypeScript8

[ESLint] naming-convention 설정방법 작성한 코드 rules: { // eslint-disable-next-line @typescript-eslint/naming-convention "@typescript-eslint/naming-convention": [ "warn", { selector: "typeAlias", // 타입선언 format: ["PascalCase"], }, { selector: "memberLike", // Property 멤버 format: ["camelCase"], }, { selector: "function", // exported function (컴포넌트 명) format: ["PascalCase"], modifiers: ["exported"], }, { selector: "function", // functio.. 2023. 11. 23.
[TypeScript] GENERIC Basic (그래서, T야?) 배경 생각해보면, 예전에 교수님 수업시간에 C언어 설명하실 때도, GENERIC으로 표현된 C언어 함수를 보여주셨던 것 같다. 그 때는, 거의 코딩을 모르는 상태라서 아예 못알아봤던 것 같고 늘 모르고 살던 것을 알았을 때의 "개안" 상태가 된 것 같다. 늘.. T가 뭐지? 하면서 라이브러리나 github 소스코드를 보곤 했었으니까.. 문제 function checkNotNull(arg: number | null): number { if (arg == null) { throw new Error("not valid number!"); } return arg; } const result = checkNotNull(23); console.log(result); checkNotNull(null); 위와 같이 작.. 2023. 8. 22.
비공개 - [TypeScript] 활용법 Basic (이 건 뭐고, 저 건 또 뭐야? 싶을 때 보는) 보호되어 있는 글 입니다. 2023. 7. 10.
[TypeScript] as 사용에 대한 이해 (feat. Type Assertions) 찾게된 이유 & 해결 ... // 에러 상황 data: data?.map(price => Number(price.close)), ... // 발생된 에러 TS2769: No overload matches this call. Overload 1 of 2, '(props: Props | Readonly): ReactApexChart', gave the following error. Type '{ name: string; data: number[] | undefined; }' is not assignable to type 'number'. Overload 2 of 2, '(props: Props, context: any): ReactApexChart', gave the following error. Type .. 2022. 12. 27.
[React / TypeScript] props를 구조분해할당으로 전달받을 때 Type Error (TS2322) 문제상황 TS2322: Type '{ data: ReservationDataType[]; }' is not assignable to type 'IntrinsicAttributes & ReservationDataType[]'. Property 'data' does not exist on type 'IntrinsicAttributes & ReservationDataType[]'. // 부모 컴포넌트 import React from "react"; import RenderComponent from "./RenderComponent"; import type { ReservationDataType } from "interface/interface"; const ReservationList = () => { // .. 2022. 12. 20.
[TypeScript] Tip - 자동으로 Type 추출 API 에서 받아오는 Data같은 경우 Type을 직접 interface로 작성해주려면 귀찮다. 아래 사이트에서 json copy & paste 하면 interface 자동으로 추출해줌. https://app.quicktype.io/?l=ts Instantly parse JSON in any language | quicktype app.quicktype.io 2022. 12. 19.