microsoft / microsoft/TypeScript
Compilation dependencies with mixins
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ả
Bug Report
When using incremental compilation with typescript (3.x and 4.x), it seems that the compiler considers any change to a mixin class as requiring recompilation of all clients and subclasses of that class.
For non-mixin classes, it seems that the compiler does not force recompilation for clients and subclasses when a method body is changed or when a hard private (e.g. #x: number) member is changed (added/removed/type changed) (it is unclear how dependencies are calculated for soft private members).
The cause seems to be, somehow, in the type inferred for the mixin function result, but this type should not depend on method bodies and privates.
🔎 Search Terms
incremental compilation
mixins
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
In the code below, we have 4 files:
Mixin is a basic mixin
Class is a similar class,
Client is a client that uses both Mixin and Class
Subclass is a file with subclasses for Mixin and Class
//File: Mixin.ts
type Constructor<T = object> = new (...args: any[]) => T;
export const Mixin = <TBase extends Constructor>(Base: TBase) => {
abstract class Mixin extends Base {
private f(): number {...}
protected g(): number {...}
h(): number {...}
#x: number;
private y: number;
protected z: number;
w: number;
}
return Mixin;
};
type AnyFunction<A = any> = (...input: any[]) => A;
type Mixin<T extends AnyFunction> = InstanceType<ReturnType<T>>
export type TMixin = Mixin<typeof TMixin>;
//File Class:
export class Class {
private f(): number {...}
protected g(): number {...}
h(): number {...}
#x: number;
private y: number;
protected z: number;
w: number;
}
//File Subclass:
class MixinSubclass extends Mixin(Object) {}
class ClassSubclass extends Class {}
//File Client:
class Client {
x: TMixin;
y: Class;
}
//(we did not include import statements)
// We can quickly address your report if:
// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
// - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
// - We have to pare too much extraneous code.
// - We have to clone a large repo and validate that the problem isn't elsewhere.
// - The sample is confusing or doesn't clearly demonstrate what's wrong.
🙁 Actual behavior
We have observed that any change to Mixin - that is, to Mixin.#x|y|z|w and even the bodies of f(),g(),h() causes recompilation of both Client.ts and Subclass.ts,
If we modify Class.#x|y|f() we do not observe recompilation of Client.ts or Subclass.ts, and if we modify Class.z|g() we do not observe recompilation of Client.ts, as expected.
In addition modifying method bodies in Class do not cause any recompilation, and as well adding more imports or non-exported declarations
🙂 Expected behavior
For Mixin, we would expect that only changing h() and w will recompile Client.ts and in addition changing g() and z will recompile Subclass.ts, we also expect that modifying any of the method bodies including h() and g(), will not recompile any other file, unless the body is used to infer the return type of the method (and then only if the return type actually changed).
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 bản tái hiện TypeScript Playground được liên kết và so sánh việc biên dịch lại gia tăng cho Mixin.ts, Class, Subclass và Client. Xác minh những chỉnh sửa nào kích hoạt việc biên dịch lại các thành phần phụ thuộc; hoàn tất có nghĩa là các dependency của mixin chỉ giới hạn ở những thay đổi kiểu public hoặc protected bị ảnh hưởng, trong khi các thay đổi trong thân phương thức không biên dịch lại các client trừ khi kiểu trả về được suy luận 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ệ
- 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
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100