Socket.io: ํƒ€์ดํ”„ ์Šคํฌ๋ฆฝํŠธ ์ปดํŒŒ์ผ ์˜ค๋ฅ˜

์— ๋งŒ๋“  2020๋…„ 11์›” 06์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: socketio/socket.io

๋‹น์‹ ์€ :

  • [x] ๋ฒ„๊ทธ๋ณด๊ณ 
  • [] ๊ธฐ๋Šฅ ์š”์ฒญ

ํ˜„์žฌ ํ–‰๋™

typescript์—์„œ javascript๋กœ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๋Š” ๋ฐ ๋ช‡ ๊ฐ€์ง€ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
namespace.d.ts ๋ฐ socket.d.ts์˜ ์œ ํ˜• ์˜ค๋ฅ˜๋กœ ์ธํ•ด ์ปดํŒŒ์ผ์ด ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค. Namespace ๋ฐ Socket ํด๋ž˜์Šค๋Š” EventEmitter๋ฅผ ํ™•์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ '๋ฐฉ์ถœ'๊ธฐ๋Šฅ์„ ์žฌ์ •์˜ํ•˜๊ณ  ์„œ๋ช…์€ EventEmitter์˜ ๋ฐฉ์ถœ ๊ธฐ๋Šฅ๊ณผ ํ˜ธํ™˜๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๊นŒ?

์žฌํ˜„ ๋‹จ๊ณ„ (ํ˜„์žฌ ๋™์ž‘์ด ๋ฒ„๊ทธ ์ธ ๊ฒฝ์šฐ)

์•„๋ž˜๋Š” ๋‚ด tsconfig ์„ค์ •์ž…๋‹ˆ๋‹ค.

{
    "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./dist",
        "lib": ["es5", "es6"],
        "target": "es3",
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "allowSyntheticDefaultImports": true,
    },
    "include": ["./src/**/*"],
}

๋‹ค์Œ์€ ํ”„๋กœ์ ํŠธ์˜ ์ข…์†์„ฑ์ž…๋‹ˆ๋‹ค.

"dependencies": {
    "debug": "^3.1.0",
    "koa": "^2.13.0",
    "socket.io": "^3.0.0"
  },
  "devDependencies": {
    "@types/koa": "^2.11.6",
    "@types/node": "^14.14.6",
    "supervisor": "^0.12.0",
    "typescript": "^4.0.5"
  }

์‹คํ–‰ํ•  ๋•Œ : 'tsc', ๋‹ค์Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

node_modules/socket.io/dist/namespace.d.ts(89,5): error TS2416: Property 'emit' in type 'Namespace' is not assignable to the same property in base type 'EventEmitter'.
  Type '(ev: string, ...args: any[]) => Namespace' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
    Type 'Namespace' is not assignable to type 'boolean'.
node_modules/socket.io/dist/socket.d.ts(84,5): error TS2416: Property 'emit' in type 'Socket' is not assignable to the same property in base type 'EventEmitter'.
  Type '(ev: string, ...args: any[]) => this' is not assignable to type '(event: string | symbol, ...args: any[]) => boolean'.
    Type 'this' is not assignable to type 'boolean'.
      Type 'Socket' is not assignable to type 'boolean'.

์„ค์ •

  • ์šด์˜์ฒด์ œ : Windows
  • socket.io ๋ฒ„์ „ : 3.0.0

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ด ๋ฒ„์ „์„ ์ตœ๋Œ€ํ•œ ๋นจ๋ฆฌ ์ถœ์‹œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๋˜๋Š” fix/typescript-emit ์ง€์ ์„ ์ง์ ‘ ํƒ€๊ฒŸํŒ…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

๋ชจ๋“  7 ๋Œ“๊ธ€

์—ฌ๊ธฐ์— ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!

๊ฐ™์€ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
๋ฐ๋น„์•ˆ, socket.io 3.0

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ์žฌํ˜„ ํ•  ์ˆ˜์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ https://github.com/socketio/socket.io/commit/50671d984a81535a6a15c704546ca7465e2ea295์— ์˜ํ•ด ์ˆ˜์ •๋˜์–ด์•ผํ•ฉ๋‹ˆ๋‹ค

์ด ๋ฒ„์ „์„ ์ตœ๋Œ€ํ•œ ๋นจ๋ฆฌ ์ถœ์‹œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๋˜๋Š” fix/typescript-emit ์ง€์ ์„ ์ง์ ‘ ํƒ€๊ฒŸํŒ…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

์ด๊ฒƒ์€ 3.0.1 ๋ฆด๋ฆฌ์Šค์˜ ๊ฐ€์น˜๊ฐ€์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

3.0.1 ์ด ๋‚˜์™”์Šต๋‹ˆ๋‹ค!

์—ฌ๊ธฐ TypeScript ์˜ˆ์ œ๋ฅผ ์—…๋ฐ์ดํŠธํ–ˆ์Šต๋‹ˆ๋‹ค : https://github.com/socketio/socket.io/tree/master/examples/typescript

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰