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

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

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

public async cancelBooking(
    internalBookingId: number,
    company: Companies,
    dataStoreService: DataStoreService,
    bookingsService: BookingsService,
  ): Promise<void>;
  public async cancelBooking(
    booking: ExtendedBookingSystemBooking,
    company: Companies,
    dataStoreService: DataStoreService,
    bookingsService: BookingsService,
  ): Promise<void>;
  public async cancelBooking(
    booking: number | ExtendedBookingSystemBooking,
    company: Companies,
    dataStoreService: DataStoreService,
    bookingsService: BookingsService,
  ) {
    ...
  }

然后从代码的其他部分调用此方法,并使用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实验

vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627:30244334
vscorecescf:30445987
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
vscaat:30438848
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonnoceb:30805159
asynctok:30898717
pythonregdiag2:30936856
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
724cj586:31013169
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
refactort:31101459
pythonrstrctxtcf:31093870
wkspc-onlycs-t:31102394
watbbzwu

watbbzwu2#

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

我尝试过:

declare function foo(str: string): void;
declare function foo(num: number): void;

foo("string");

foo(12345);
tjjdgumg

tjjdgumg3#

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

class ZZZ {
  id: number;
}

class CCC {
  activities: number[];
}

class XYZ {
  public async cancelBooking(
    internalBookingId: number,
    company: ZZZ,
  ): Promise<void>;
  public async cancelBooking(booking: CCC, company: ZZZ): Promise<void>;
  public async cancelBooking(booking: number | CCC, company: ZZZ) {}

  public async XYZ() {
    return this.cancelBooking(
      { activities: [1, 2, 3] },
      {
        id: 1,
      },
    );
  }
}
mkshixfv

mkshixfv4#

type HasID = {
  id: number;
}

type Numbers = {
  n: number[];
}

declare function func(bad1: number, bad2: HasID): void;
declare function func(ok_1: Numbers, ok_2: HasID): void;

// Inlay hint shows bad1/bad2, should show ok_1/ok_2
func(
  { n: [1, 2, 3] },
  {
    id: 1,
  },
);

相关问题