microsoft / microsoft/TypeScript

Method use showing as deprecated when callback function includes type hint

Đang mở
#59,488 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Needs More Info
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

Type: Bug

Using jQuery globally, I noticed that the usage of .on() is showing as deprecated when my event handler function includes a typehint. I could be wrong but I don't believe this is due to the type definitions and might be something with TS.

The below shows .on with a strikethrough that it is deprecated.

$(document).on("click", ".search-tag", /** @this {HTMLElement} */ function() {
    selectedKeywords.delete(this.dataset.module);
    $(this).remove();
});

image

Removing the typehint from the callback makes the deprecation notice go away.

$(document).on("click", ".search-tag", function() {
    selectedKeywords.delete(this.dataset.module);
    $(this).remove();
});

image

Below is what the hover shows for the deprecation:
image

It seems the be complaining about the use of JQueryEventObject but only when the type hint is present.

VS Code version: Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729, 2024-07-09T22:06:49.809Z)
OS version: Windows_NT x64 10.0.22631
Modes:
Remote OS version: Linux x64 4.18.0-553.8.1.el8_10.x86_64

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-1360P (16 x 2611)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.68GB (18.95GB free)
Process Argv --folder-uri vscode-remote://ssh-remote%2Bmlinks-dev/home/cgoepfrich2/public_html/mlinks
Screen Reader no
VM 0%
Item Value
Remote SSH: mlinks-dev
OS Linux x64 4.18.0-553.8.1.el8_10.x86_64
CPUs Intel(R) Xeon(R) Gold 6230R CPU @ 2.10GHz (2 x 0)
Memory (System) 7.52GB (1.23GB free)
VM 100%
Extensions (25)
Extension Author (truncated) Version
ccl-tools DSH 0.0.11
vscode-apache mrm 1.2.0
vscode-edge-devtools ms- 2.1.5
jupyter-keymap ms- 1.1.2
remote-containers ms- 0.375.1
remote-ssh ms- 0.112.0
remote-ssh-edit ms- 0.86.0
remote-wsl ms- 0.88.2
vscode-remote-extensionpack ms- 0.25.0
remote-explorer ms- 0.4.3
remote-server ms- 1.5.2
vscode-jsp pth 0.0.3
pdf tom 1.2.2
highlight-matching-tag vin 0.11.0
vscode-intelephense-client bme 1.10.4
vscode-svgviewer css 2.0.0
transformer dak 1.12.1
gitlens eam 15.2.3
gitlab-workflow Git 5.2.0
todo-tree Gru 0.0.226
vscode-dotnet-runtime ms- 2.1.1
vsliveshare ms- 1.0.5936
vscode-xml red 0.27.1
vscode-yaml red 1.15.0
php-debug xde 1.35.0

(1 theme extensions excluded)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ jQuery-.on() được cung cấp trong VS Code, cả khi có và khi không có gợi ý kiểu JSDoc @this {HTMLElement}, sau đó theo dõi cách TypeScript xử lý callback và overload đã bị deprecated. Hoàn tất khi cách sử dụng .on() hợp lệ không còn bị đánh dấu là deprecated khi có gợi ý kiểu, đồng thời có một bài kiểm thử hồi quy bao quát cả hai ví dụ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, jquery, typescript
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.