microsoft / microsoft/TypeScript
JavaScript class property becomes `any` without warning when used in a function that is assigned to itself
Đang mở
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ả
🔎 Search Terms
jsdoc class null any
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
any
⏯ Playground Link
💻 Code
export class Foo {
/**
* @param {number?} maybeNum
*/
constructor(maybeNum) {
this.maybeNum = null;
this.setMaybeNum();
}
setMaybeNum() {
this.maybeNum = Math.max(this.maybeNum);
}
/**
* @param {string} str
*/
takesString(str) {}
foo() {
this.takesString(this.maybeNum);
// ^^^^^^^^^^^^^---- no error, maybeNum is any
}
}
🙁 Actual behavior
this.maybeNum is any
🙂 Expected behavior
this.maybeNum is number | null or (since noImplicitAny is set) an error is emitted warning the user that this.maybeNum is any.
Additional information about the issue
It seems like the core issue here is this line:
this.maybeNum = Math.max(this.maybeNum);
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 ví dụ TypeScript Playground được liên kết và phép gán this.maybeNum = Math.max(this.maybeNum) trong lớp JavaScript. Theo dõi cách phép gán đó ảnh hưởng đến lệnh gọi takesString(this.maybeNum) sau đó, rồi xác minh bản sửa lỗi dựa trên kiểu number | null dự kiến hoặc chẩn đoán noImplicitAny.
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
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100