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'.
์ฌ๊ธฐ์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค!
๊ฐ์ ๋ฌธ์ ์
๋๋ค.
๋ฐ๋น์, 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
๊ฐ์ฌํฉ๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ๋ฒ์ ์ ์ต๋ํ ๋นจ๋ฆฌ ์ถ์ ํ ์ ์์ต๋๊น?
๋๋
fix/typescript-emit
์ง์ ์ ์ง์ ํ๊ฒํ ํ๊ฒ ์ต๋๋ค!