microsoft / microsoft/TypeScript
Improve feedback for abstract class instantiation error messages
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
SUGGESTION
Recently, I was trying to use a library written in ES2015 in an Ionic 2 project, and kept getting a Cannot instantiate abstract class 'Foo'. Foo is a concrete class that extends abstract class Bar, which extends abstract class Baz. The problem turned out to be a typo in Bar.d.ts (see below), which (I believe) made Typescript think that Foo did not implement some abstract methods of Bar and/or Baz (I'm still not sure which), but it took me a day and half to figure out what was going on. This error message should have more information about why Foo is abstract: Foo is declared as abstract or Foo does not implement abstract methods ...
TypeScript Version: 2.0.9
Code
Baz.d.ts
export as namespace Baz;
declare abstract class Baz {
abstract baz(): string;
}
Bar.d.ts
export as namespace BarTypo;
declare abstract class Bar extends Baz {
abstract foo(): void;
abstract bar(): string;
baz(): string;
}
export { Bar };
Foo.d.ts
import { Bar } from './bar.d';
export as namespace Foo;
declare class Foo extends Bar {
constructor(opts?);
foo(): void;
bar(a: string): string;
}
export { Foo };
otherProject.ts
import { Foo } from 'library';
export class Service {
foo: Foo;
constructor() {
this.foo = new Foo({ opt: true });
}
}
Expected behavior:
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): baz.
OR
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): foo, bar.
OR
Error: Cannot instantiate abstract class 'Foo'. It does not implement abstract method(s): baz (from Baz); foo, bar (from Bar).
Actual behavior:
Error: Cannot instantiate abstract class 'Foo'.
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 bằng cách tái hiện chẩn đoán với Baz.d.ts, Bar.d.ts, Foo.d.ts và otherProject.ts, sử dụng hành vi của TypeScript 2.0.9 được mô tả ở đây. Truy vết lỗi khởi tạo lớp trừu tượng của trình biên dịch và làm cho thông báo xác định các phương thức trừu tượng hoặc khai báo liên quan bị thiếu. Được xem là hoàn tất khi ví dụ báo cáo lý do Foo không thể được khởi tạo, khớp với một trong các thông báo dự kiến được đề xuất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- 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