Closed matvejs16 closed 8 months ago
Type: Bug
Getting typescript error on "event" variable in events.on method:
Argument of type 'keyof IClientEvents' is not assignable to parameter of type 'string'. Type 'number' is not assignable to type 'string'.ts(2345)
Steps to reproduce:
type IClientEvents = { [event: string]: (...args: any[]) => void; testClient: (arg: string) => void; testClient2: (arg: string) => void; }
const customEvents: Map<string, Function[]> = new Map(); const events = { on(event: T, callback: IClientEvents[T]) { if (!customEvents.has(event)) customEvents.set(event, []); // getting error on "event" customEvents.get(event)?.push(callback); } }
VS Code version: Code - Insiders 1.87.0-insider (00124e9e5830e3efc897db71c781899f8a676295, 2024-02-16T16:33:57.085Z) OS version: Windows_NT x64 10.0.22631 Modes: <details> <summary>System Info</summary> |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 x 3600)| |GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.87GB (22.95GB free)| |Process Argv|E:\\Coding Scripts\\Vue\\SocketIO-TS-Module-Test --crash-reporter-id c1f0a67e-8694-4f1d-abf8-047a7ae97861| |Screen Reader|no| |VM|0%| </details><details><summary>Extensions (69)</summary> Extension|Author (truncated)|Version ---|---|--- vscode-css-formatter|aes|1.0.2 TabOut|alb|0.2.2 Bookmarks|ale|13.4.2 vscode-color|ans|0.4.5 ejs-snippets-and-color-highlighting|Ayu|0.0.5 vscode-intelephense-client|bme|1.10.2 npm-intellisense|chr|1.4.5 path-intellisense|chr|2.8.5 format-json|Cle|1.0.3 vscode-eslint|dba|2.4.4 jquerysnippets|don|0.0.1 gitlens|eam|14.8.2 vscode-html-css|ecm|2.0.9 apacheconf-snippets|eim|1.3.0 prettier-vscode|esb|10.1.0 auto-close-tag|for|0.5.15 auto-rename-tag|for|0.1.10 vscode-mysql|for|0.5.0 copilot|Git|1.162.714 copilot-chat|Git|0.12.2 py-paste-indent|hye|0.3.0 fontawesome-autocomplete|Jan|1.3.1 vscode-peacock|joh|4.2.2 vsc-python-indent|Kev|1.18.0 rainbow-csv|mec|3.11.0 dotenv|mik|1.0.1 vscode-nbt|Mis|0.9.1 websocket-client|moh|0.2.0 vscode-html-format|moh|0.1.6 prettify-json|moh|0.0.3 theme-monokai-pro-vscode|mon|1.2.2 vscode-less|mrm|0.6.3 vscode-language-pack-ru|MS-|1.85.2024021409 csharp|ms-|2.15.30 vscode-dotnet-runtime|ms-|2.0.1 debugpy|ms-|2024.0.0 isort|ms-|2023.10.1 python|ms-|2024.0.1 vscode-pylance|ms-|2024.2.2 remote-wsl|ms-|0.86.0 cmake-tools|ms-|1.17.15 cpptools|ms-|1.19.3 cpptools-extension-pack|ms-|1.3.0 hexeditor|ms-|1.9.13 vscode-typescript-next|ms-|5.4.20240218 vsliveshare|ms-|1.0.5905 sftp|Nat|1.16.3 prettier-vscode-with-tabs|pas|1.1.0 total-lines|pra|0.0.1 vscode-css-navigation|puc|1.14.0 pawn|Qoo|0.0.3 format-html-in-php|rif|1.7.0 LiveServer|rit|5.7.9 postcode|roh|1.3.9 markdown-preview-enhanced|shd|0.8.11 vscode-scss-formatter|sib|3.0.0 sass-indented|syl|1.8.29 ejs-snippets|Tao|0.1.0 vscode-fontawesome-gallery|tom|0.0.7 cmake|twx|0.0.17 vscode-icons|vsc|12.7.0 volar|Vue|1.8.27 vscode-typescript-vue-plugin|Vue|1.8.27 quokka-vscode|Wal|1.0.627 vscode-todo-highlight|way|1.0.5 JavaScriptSnippets|xab|1.8.0 php-debug|xde|1.34.0 php-pack|xde|1.0.3 php-intellisense|zob|1.3.3 (2 theme extensions excluded) </details><details> <summary>A/B Experiments</summary>
vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256197 vscod805:30301674 vsaa593:30376534 py29gd2263:30784851 c4g48928:30535728 a9j8j154:30646983 962ge761:30841072 pythongtdpath:30726887 welcomedialog:30812478 pythonidxpt:30768918 pythonnoceb:30776497 asynctok:30898717 dsvsc013:30777762 dsvsc014:30777825 dsvsc015:30821418 pythontestfixt:30866404 pythonregdiag2:30926734 pyreplss1:30879911 pythonmypyd1:30859725 pythoncet0:30859736 2e7ec940:30962249 pythontbext0:30879054 accentitlementst:30870582 dsvsc016:30879898 dsvsc017:30880771 dsvsc018:30880772 cppperfcontrol:30963551 8082a590:30961435 b5d27386:30943795 fegfb526:30952798 7j2b6412:30951517 e3gdj431:30946825 78248357:30959762 ccp2r6:30958154
</details> <!-- generated by issue reporter -->
This is a TypeScript issue not a VSCode issue, it happens in TSPlayround as well.
Type: Bug
Getting typescript error on "event" variable in events.on method:
Steps to reproduce:
const customEvents: Map<string, Function[]> = new Map(); const events = { on(event: T, callback: IClientEvents[T]) {
if (!customEvents.has(event)) customEvents.set(event, []); // getting error on "event"
customEvents.get(event)?.push(callback);
}
}
vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256197 vscod805:30301674 vsaa593:30376534 py29gd2263:30784851 c4g48928:30535728 a9j8j154:30646983 962ge761:30841072 pythongtdpath:30726887 welcomedialog:30812478 pythonidxpt:30768918 pythonnoceb:30776497 asynctok:30898717 dsvsc013:30777762 dsvsc014:30777825 dsvsc015:30821418 pythontestfixt:30866404 pythonregdiag2:30926734 pyreplss1:30879911 pythonmypyd1:30859725 pythoncet0:30859736 2e7ec940:30962249 pythontbext0:30879054 accentitlementst:30870582 dsvsc016:30879898 dsvsc017:30880771 dsvsc018:30880772 cppperfcontrol:30963551 8082a590:30961435 b5d27386:30943795 fegfb526:30952798 7j2b6412:30951517 e3gdj431:30946825 78248357:30959762 ccp2r6:30958154