티스토리 뷰

Typescript기반 NestJS에서는 DTO를 interface가 아닌 class로 선언한다.

그 이유는 TypeScript의 클래스는 JavaScript ES6 표준을 따른다. 컴파일된 JavaScript에서 class는 실제 엔터티로 보존되는 반면에 interface는 변환 중에 제거되기 때문에 런타임 시 NestJS는 인터페이스를 참조하지 못한다.

 

참고

https://docs.nestjs.com/controllers#request-payloads

 

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 Progamming), FP (Functional Programming), and FRP (Functional Reac

docs.nestjs.com

 

 

출처 : https://www.inflearn.com/questions/526436

 

DTO 를 interface가 아닌 class로 해주는 이유가 있나요? - 인프런 | 질문 & 답변

보면 instance를 생성하는 것이 아닌 type check 정도만 해주는거 같은데 interface가 아닌 class 로 써주는 이유가 있나요? - 질문 & 답변 | 인프런...

www.inflearn.com

 

 

'Node.js > Nest.js' 카테고리의 다른 글

[NestJS] 1. NestJS 시작하기  (0) 2022.05.22
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함