ZeroCho / nodejs-book

Node.js교과서 소스 코드
803 stars 642 forks source link

[p.807] global scope 설정에 대해 IDE별 다른 동작 #780

Closed wiseguy77 closed 1 year ago

wiseguy77 commented 1 year ago

오류나 오타에 대한 문제가 아닌 VSCode가 아닌 IDE에서 다르게 동작하는 부분에 대한 문의 입니다.

인터페이스 선언 병합을 위해서 Error 인터페이스에 status 속성 추가 시 declare global 전역 스코프를 사용할 때,

VSCode에서는 잘 동작했지만, IntelliJ에서 실행할 경우에는 이 스코프 코드(declare global{})를 주석 처리 해야 동작합니다. 반대로 주석처리하게 되면 VSCode에서는 인터페이스 병합이 되질 않아 status 속성관련 컴파일 에러가 발생하구요. 혹시 이유를 알고 계신다면 공유 부탁드립니다.

IntelliJ 버전 : 2021.1.3 Ultimate Edition

교재 내용 자체에 대한 문의가 아님에도 어디에 문의를 드려야 할 지 정확히 몰라서 여기에 질문드린 점 양해 부탁드립니다. 혹시 이런 질문을 드릴 수 있는 경로가 별도로 있다면 알려주시길 부탁드립니다.

ZeroCho commented 1 year ago

전체 코드 보여주세요. declare global 아래에 export {} 도 존재하나요?

wiseguy77 commented 1 year ago

안녕하세요.

  1. 말씀해주신대로 마지막에 export{} 를 추가하니 Error.status 추가 속성 에러는 없어졌습니다. 그런데 책에서도 마지막에 export {}를 하지 않았고 그럼에도 VSCode에서는 에러가 안나는 것이 이상하네요.

  2. 소스 내에 Sequelize 관련 코드들에도 IntelliJ에서는 빨간줄이 생기며 아래와 같이 상황별 에러메시지가 나옵니다.

    • models/index.ts Line 10: export const sequelize = new Sequelize.Sequelize(config.database, config.username, config.password, config);

    • [IntelliJ 에러 메시지] Argument type {password: string, database: string, dialect: string, host: string, username: string} | {password: string, database: string, dialect: string, host: string, username: string} | {password: string, database: string, dialect: string, host: string, logging: boolean, username: string} is not assignable to parameter type Options | undefined

    • models/hashtag Line 42: Hashtag.belongsToMany(Post, { through: "PostHashtag" });

    • models/post Line 48, 49 : Post.belongsTo(User) , Post.belongsToMany( Hashtag, { through: "PostHashtag" }

    • models/user Line 69-78 : User.belongsTo(User, ... ) , User.belongsToMany(User, ...)

    • [IntelliJ 에러 메시지] Argument type User is not assignable to parameter type ModelStatic

  3. 모델 객체들을 이용한 메서드(findOne, create) 사용 시 전달하는 인수들에 빨간줄 발생

    • controllers/auth.ts Line 11 : User.findOne({ where: { email } });

    • [IntelliJ 에러 메시지] Argument type {where: {email: any}} is not assignable to parameter type NonNullFindOptions<Attributes>

    • controllers/auth.ts Line 17 : await User.create({ email, nick, password: hash });

    • [IntelliJ 에러 메시지] Argument type {nick: any, password: string, email: any} is not assignable to parameter type CreationAttributes | undefined

4,. 이상한 것은 2, 3번의 경우 IntelliJ 툴에서 빨간줄로 오류 메시지를 발생시키지만 터미널에서 tsc 컴파일할 때는 에러가 발생하지 않습니다.

교재 내용과 다른 환경에서 발생한 문제 대응에 감사드립니다. 전체 소스를 첨부합니다.

고맙습니다. 명한 드림.

nodejs-ts-master.zip https://drive.google.com/file/d/1PJxlKL2Tlbs-0lqFAc-X9ZNqNJ4FH_F2/view?usp=drive_web

2023년 7월 8일 (토) 오후 8:23, Hyunyoung Cho @.***>님이 작성:

전체 코드 보여주세요. declare global 아래에 export {} 도 존재하나요?

— Reply to this email directly, view it on GitHub https://github.com/ZeroCho/nodejs-book/issues/780#issuecomment-1627140666, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACM3KGEHOI52GEEP43TDCO3XPE7L5ANCNFSM6AAAAAA2CTXWZE . You are receiving this because you authored the thread.Message ID: @.***>

ZeroCho commented 1 year ago
  1. 책에서는 import가 있어서 괜찮은 겁니다. 최상위 스코프에 import/export가 존재하면 declare global은 정상 작동합니다. 참고영상
  2. 제가 코드를 다운받아서 해보니 빨간 줄이 생기지는 않네요. 이거 intellij의 ts 서버가 느리거나 해서 그럴 수 있습니다. 인텔리제이를 껐다 켜거나 컴퓨터를 껐다 켜면 해결되기도 합니다.
  3. 2번가 마찬가지
  4. tsc를 믿으시면 됩니다. tsc에서 나오는 에러들만이 진짜 에러입니다.
wiseguy77 commented 1 year ago

안녕하세요 제로초님,

  1. 보내주신 영상자료가 이해하는데 큰 도움이 되었습니다. 2, 3. IntelliJ의 문제인 것 같습니다.
  2. 이후엔 tsc 실행결과를 중심으로 진행 해야겠습니다.

문제 해결에 큰 도움이 되었습니다. 고맙습니다.

명한 드림.

2023년 7월 9일 (일) 오후 3:04, Hyunyoung Cho @.***>님이 작성:

  1. 책에서는 import가 있어서 괜찮은 겁니다. 최상위 스코프에 import/export가 존재하면 declare global은 정상 작동합니다. 참고영상 https://www.youtube.com/watch?v=HZ0PhDhM-S4
  2. 제가 코드를 다운받아서 해보니 빨간 줄이 생기지는 않네요. 이거 intellij의 ts 서버가 느리거나 해서 그럴 수 있습니다. 인텔리제이를 껐다 켜거나 컴퓨터를 껐다 켜면 해결되기도 합니다.
  3. 2번가 마찬가지
  4. tsc를 믿으시면 됩니다. tsc에서 나오는 에러들만이 진짜 에러입니다.

— Reply to this email directly, view it on GitHub https://github.com/ZeroCho/nodejs-book/issues/780#issuecomment-1627616167, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACM3KGCR2RUBDLWJJC7HBMLXPJCYXANCNFSM6AAAAAA2CTXWZE . You are receiving this because you authored the thread.Message ID: @.***>

wiseguy77 commented 1 year ago

2, 3번 문제는 최신버전(2023.1.3 Ultimate) IntelliJ 설치 후엔 발생하지 않습니다. 제가 사용한 버전(2021.1.3 Ultimate)에서만 발생하는 문제인 것으로 보입니다. 관련 릴리즈 노트를 검색해 봤지만 관련 내용을 찾지는 못했습니다.

답변 고맙습니다.

2023년 7월 9일 (일) 오후 5:09, mh h @.***>님이 작성:

안녕하세요 제로초님,

  1. 보내주신 영상자료가 이해하는데 큰 도움이 되었습니다. 2, 3. IntelliJ의 문제인 것 같습니다.
  2. 이후엔 tsc 실행결과를 중심으로 진행 해야겠습니다.

문제 해결에 큰 도움이 되었습니다. 고맙습니다.

명한 드림.

2023년 7월 9일 (일) 오후 3:04, Hyunyoung Cho @.***>님이 작성:

  1. 책에서는 import가 있어서 괜찮은 겁니다. 최상위 스코프에 import/export가 존재하면 declare global은 정상 작동합니다. 참고영상 https://www.youtube.com/watch?v=HZ0PhDhM-S4
  2. 제가 코드를 다운받아서 해보니 빨간 줄이 생기지는 않네요. 이거 intellij의 ts 서버가 느리거나 해서 그럴 수 있습니다. 인텔리제이를 껐다 켜거나 컴퓨터를 껐다 켜면 해결되기도 합니다.
  3. 2번가 마찬가지
  4. tsc를 믿으시면 됩니다. tsc에서 나오는 에러들만이 진짜 에러입니다.

— Reply to this email directly, view it on GitHub https://github.com/ZeroCho/nodejs-book/issues/780#issuecomment-1627616167, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACM3KGCR2RUBDLWJJC7HBMLXPJCYXANCNFSM6AAAAAA2CTXWZE . You are receiving this because you authored the thread.Message ID: @.***>