microsoft / microsoft/TypeScript
Type a standard import with jsdoc only
Chưa có ai nhận issue này.
- 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
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ 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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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