본문 바로가기

개발/typescript

[NestJs] Params, Query, Body controller를 통해 요청을 받으면, client에서 올린 데이터를 약속된 방식에 따라 정리? 해야한다. 아래는 각 케이스별 컨트롤러에서의 코드이다. import { Body, Controller, Post, Get, Query, Param } from "@nestjs/common"; import { userMookService, UserMockInterface } from "user/user.service"; import { UserDTO } from "user/dto/user.dto"; @Controller("user") export class UserController { // state 설정을 해줘야, constructor 안에서 사용 가능 private service: userMookSer.. 더보기
[NestJs] Validation이 안되요... Controller, Module, Provider(DI, IOC)개념을 아래 링크를 통해 익힐수 있다. https://docs.nestjs.com/first-steps Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Func.. 더보기
[TS] Catch clause variable type annotation must be 'any' or 'unknown' if specified. try/catch사용시 발생하는 에러입니다. catch로 에러를 잡을때, catch(e)의 e로 에러 문구를 확인할수 있는데요. 위 내용은 말 그대로 e에 대해 타입을 지정해줄거면 any or unkown을 사용하라는 말입니다. # any일 경우 try{ ... }catch(e: any){ ... } # unkown일 경우 try{ ... }catch(e: unkown){ ... } 이상입니다 더보기
[Typescript] Module '"react-router-dom"' has no exported member 'useHistory'. react(ts)에서 router로 페이지를 이동시키려 할때 useHistory를 사용하려하니 위 경고문이 떴습니다. 해결책은 useNavigate 사용입니다 import { useNavigate } from 'react-router-dom'; const navigate = useNavigate(); # useEffect안에서만 사용 가능합니다 useEffect(() => { navigate('/home'); },[]) 이상입니다 더보기
[Typescript] Object is of type 'unknown' ts 사용중 위 에러가 뜨면 type지정을 통해 해결 가능합니다. react에서 useSelector를 사용하는 경우를 보겠습니다. # error 발생 const todos = useSelector(state => state.user); # useSelector 타입 지정 const todos = useSelector(state => state.user); 이상입니다 더보기
type concat typescript에서 가장 번거로운건 매개변수별 타입을 정해주는 것입니다. 개인적으로 공통 타입을 만들어 놓고 사용하는 것을 즐기는데요. 그럼 타입끼리 합쳐 새로운 타입을 생성하는건 어떻게 할까요? type a = {a: number} type b = {b: number} type c = a & b // c = { // a: number, // b: number // } 이상입니다 더보기
typescript+pwa 구현하기 이전 시간에 cra(create-react-app)+pwa를 구현했습니다. 이번에는 cra(create-react-app)+typescript+pwa를 구현해보겠습니다! 1. `create-react-app 파일명 --template pwa-typescript`을 진행합니다. 2. src/index.tsx의 18줄을 serviceWorkerRegistration.register()로 변경해주세요. 3. 빌드를 해줍니다 by 'npm run build'. *deploy상태에서만 pwa 적용이 가능합니다. 그런데 build를 해주면 아래와 같이 에러가 발생합니다. 에러 해결을 위해 build 결과를 localhost로 띄우겠습니다. 4. public/server.js에 파일을 생성해서 아래 코드를 넣습니다... 더보기
typescript docs 번역본 #5 (Unions and Intersection Types) 아래 링크는 원본입니다. 해석이 부족해도 양해 부탁드립니다..ㅎㅎ www.typescriptlang.org/docs/handbook/unions-and-intersections.html Handbook - Unions and Intersection Types How to use unions and intersection types in TypeScript www.typescriptlang.org ``` 지금까지 handbook은 원자 객체인 type들을 다뤄왔습니다. 그러나 더 많은 타입을 만들수록, 스크래치로부터 그들을 만들기 보단 존재하는 type들을 결합하거나 짓도록 하는 툴들을 기대하는 자신을 발견할 것입니다. Intersection과 union type은 당신이 type을 짓는 방식 중 하나 입.. 더보기