TypeScript 显示方法参数名称的特性(Feature)不能正确处理方法重载(因此变量名来自错误的重载,可能是来自第一个方法定义),

yebdmbv4  于 9个月前  发布在  TypeScript
关注(0)|答案(4)|浏览(113)

类型:Bug
当代码如下所示时:

  1. public async cancelBooking(
  2. internalBookingId: number,
  3. company: Companies,
  4. dataStoreService: DataStoreService,
  5. bookingsService: BookingsService,
  6. ): Promise<void>;
  7. public async cancelBooking(
  8. booking: ExtendedBookingSystemBooking,
  9. company: Companies,
  10. dataStoreService: DataStoreService,
  11. bookingsService: BookingsService,
  12. ): Promise<void>;
  13. public async cancelBooking(
  14. booking: number | ExtendedBookingSystemBooking,
  15. company: Companies,
  16. dataStoreService: DataStoreService,
  17. bookingsService: BookingsService,
  18. ) {
  19. ...
  20. }

然后从代码的其他部分调用此方法,并使用ExtendedBookingSystemBooking作为第一个参数,内联方法参数提示显示“internalBookingId”作为方法参数名称,尽管VSCode知道第二个方法定义被使用(在方法调用上悬停时会正确显示)。
VS Code版本:Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729, 2024-07-09T22:08:12.169Z)
操作系统版本:Linux x64 6.9.9-100.fc39.x86_64
模式:
系统信息
| 项目 | 值 |
| ------------ | ------------ |
| CPUs | Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (8 x 2899) |
| GPU状态 | 2d_canvas: enabledcanvas_oop_rasterization: disabled_offdirect_rendering_display_compositor: disabled_off_okgpu_compositing: enabledmultiple_raster_threads: enabled_onopengl: enabled_onrasterization: enabledraw_draw: disabled_off_okskia_graphite: disabled_offvideo_decode: enabledvideo_encode: disabled_softwarevulkan: disabled_offwebgl: enabledwebgl2: enabledwebgpu: disabled_off |
| 平均负载 | 2, 3, 3 |
| 内存(系统) | 31.23GB (11.54GB free) |
| 进程argv | --crash-reporter-id 42f3b124-3ec4-47eb-9930-f9dae9c4e9d6 |
| 屏幕阅读器 | no |
| VM | 0% |
| DESKTOP_SESSION | gnome-xorg |
| XDG_CURRENT_DESKTOP | GNOME |
| XDG_SESSION_DESKTOP | gnome-xorg |
| XDG_SESSION_TYPE | x11 |扩展(15)
| 扩展名 | 作者(省略) | 版本 |
| ------------ | ------------ | ------------ |
| atlascode | atl | 3.0.10 |
| vscode-eslint | dba | 3.0.10 |
| gitlens | eam | 15.2.3 |
| prettier-vscode | esb | 10.4.0 |
| auto-rename-tag | for | 0.1.10 |
| lintlens | ghm | 7.5.0 |
| copilot | Git | 1.219.0 |
| copilot-chat | Git | 0.17.1 |
| vscode-pull-request-github | Git | 0.92.0 |
| vscode-graphql | Gra | 0.11.0 |
| vscode-graphql-syntax | Gra | 1.3.6 |
| todo-tree | Gru | 0.0.226 |
| intellij-idea-keybindings | k-- | 1.7.2 |
| vscode-speech | ms- | 0.10.0 |
| vscode-yaml | red | 1.15.0 |(排除了2个主题扩展)
A/B实验

  1. vsliv368cf:30146710
  2. vspor879:30202332
  3. vspor708:30202333
  4. vspor363:30204092
  5. vswsl492:30256859
  6. vstes627:30244334
  7. vscorecescf:30445987
  8. vscod805cf:30301675
  9. binariesv615:30325510
  10. vsaa593cf:30376535
  11. py29gd2263:31024239
  12. vscaat:30438848
  13. c4g48928:30535728
  14. azure-dev_surveyone:30548225
  15. 962ge761:30959799
  16. pythongtdpath:30769146
  17. welcomedialog:30910333
  18. pythonnoceb:30805159
  19. asynctok:30898717
  20. pythonregdiag2:30936856
  21. pythonmypyd1:30879173
  22. 2e7ec940:31000449
  23. pythontbext0:30879054
  24. accentitlementst:30995554
  25. dsvsc016:30899300
  26. dsvsc017:30899301
  27. dsvsc018:30899302
  28. cppperfnew:31000557
  29. dsvsc020:30976470
  30. pythonait:31006305
  31. dsvsc021:30996838
  32. 724cj586:31013169
  33. pythoncenvpt:31062603
  34. a69g1124:31058053
  35. dvdeprecation:31068756
  36. dwnewjupyter:31046869
  37. impr_priority:31102340
  38. refactort:31101459
  39. pythonrstrctxtcf:31093870
  40. wkspc-onlycs-t:31102394
watbbzwu

watbbzwu2#

我无法复现这个问题。你能提供一个本地的代码示例,让我们看看如何演示这个问题吗?

我尝试过:

  1. declare function foo(str: string): void;
  2. declare function foo(num: number): void;
  3. foo("string");
  4. foo(12345);
tjjdgumg

tjjdgumg3#

你好,@RyanCavanaugh - 对于简单的情况,它可能运行良好。请尝试使用这个"最小化"复现器:

  1. class ZZZ {
  2. id: number;
  3. }
  4. class CCC {
  5. activities: number[];
  6. }
  7. class XYZ {
  8. public async cancelBooking(
  9. internalBookingId: number,
  10. company: ZZZ,
  11. ): Promise<void>;
  12. public async cancelBooking(booking: CCC, company: ZZZ): Promise<void>;
  13. public async cancelBooking(booking: number | CCC, company: ZZZ) {}
  14. public async XYZ() {
  15. return this.cancelBooking(
  16. { activities: [1, 2, 3] },
  17. {
  18. id: 1,
  19. },
  20. );
  21. }
  22. }
展开查看全部
mkshixfv

mkshixfv4#

  1. type HasID = {
  2. id: number;
  3. }
  4. type Numbers = {
  5. n: number[];
  6. }
  7. declare function func(bad1: number, bad2: HasID): void;
  8. declare function func(ok_1: Numbers, ok_2: HasID): void;
  9. // Inlay hint shows bad1/bad2, should show ok_1/ok_2
  10. func(
  11. { n: [1, 2, 3] },
  12. {
  13. id: 1,
  14. },
  15. );

相关问题