microsoft / microsoft/TypeScript

Type a standard import with jsdoc only

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

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

Awaiting More Feedback Domain: JavaScript Domain: JSDoc Suggestion
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ả

🔍 Search Terms

ecmascript module import jsdoc

✅ Viability Checklist
⭐ Suggestion

Right now I can type an require call with

/**
 * @type {typeof import("./accounts").userAccount}
 */
var x = require("./accounts").userAccount;

from https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types

But when I my code uses an import statement
import { shortNameFromImport } from "textmodule";
I did not found a way to type that when the module resolution does found a hit.

@type in the line before can not be used because there is no let or const in this line.

/** @type {import('textmodule')} */
import { shortNameFromImport } from "textmodule";

And the normal way to type a variable with parenthesis can not be used because it is not valid JS code:

import { /** @type {import('textmodule')} */ (shortNameFromImport ) } from "textmodule";

Both variants without parenthesis do not work...

import { /** @type {import('textmodule')} */ shortNameFromImport } from "textmodule";
import { shortNameFromImport /** @type {import('textmodule')} */ } from "textmodule";
📃 Motivating Example

With typescript code I can do some magic with path in the tsconfig.json

"paths": {
  "textmodule": [ "./textmodule.ts" ]
},

But I wanted to have a JSDoc only solution.

💻 Use Cases

See above

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 với tài liệu về các kiểu được JSDoc hỗ trợ, đặc biệt là phần import-types, và so sánh ví dụ require của phần này với các ví dụ import có tên trong issue này. Theo dõi cách TypeScript checker xử lý JSDoc trên các khai báo import JavaScript, sau đó định nghĩa các bài kiểm thử cho annotation được hỗ trợ và xác nhận rằng đầu ra JavaScript vẫn không thay đổi.

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, typescript
Lĩnh vực
compilers
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 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
25/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.