microsoft / microsoft/TypeScript

checkJs: x.js should use x.d.ts for type inference

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

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

Awaiting More Feedback 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ả

Suggestion

🔍 Search Terms

checkjs, declaration files

✅ 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 feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

If a declaration file with the same name than a JavaScript file is available (in the same location), then the declaration file should be used to check the js file.

📃 Motivating Example

Assume that "checkJs" and "strict" options are enabled.

Given the following files:

// @filename a.d.ts
export function f(n: number): number;
// @filename a.js
function f(a) {
    // Parameter 'a' implicitly has an 'any' type
    return a + 1
}

the type of f should be inferred and should thus type-check. TSC does not currently use a.d.ts to infer types of a.js.
Note that importing f in another js file, already infer f's type

// @filename b.js
import { f } from "./a.js"
// type of f is inferred

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 reproducer của checkJs và strict bằng cách sử dụng a.d.ts, a.js và b.js, sau đó chạy checker của TypeScript trên đó để xác nhận chẩn đoán hiện tại. Theo dõi cách tệp khai báo được phân giải cho f đã import và so sánh với việc kiểm tra trực tiếp a.js. Hoàn thành khi khai báo cùng tên được sử dụng để kiểm tra kiểu của a.js mà không thay đổi JavaScript được phát ra.

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
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.