microsoft / microsoft/TypeScript
Force Override Declarations Types
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
Search Terms
declaration
module
merging
override
interface
Suggestion
Add a way to force override declarations for modules in the workspace. Typescript allows you to create a global.d.ts to add global declarations. How about an override.d.ts or an *.override.d.ts file to override existing modules declarations in the user workspace.
Use Cases
Lets say you install a node module package and type. You see that the type parameter isn't type safe so you use declaration merging to create a more type safe declaration. However, when you use the module type as a variables type or choose to extending it, it automatically uses the types folder declaration first since the type parameter used fits the node_modules declaration type parameter, however that type would not fit the type parameter the user created. This is because declaration merging selects the most appropriate types in order. If the type was to not match the first declaration type it would move on until reaching the appropriate type, which wouldn't work in this use case.
Examples
// Node Module module declaration file
declare module "react-router" {
interface RouteComponentProps<Params extends { [K in keyof Params]?: string | undefined }> {
params: Params;
}
}
// User Defined Type declaration file
export type NoRequired<T extends {}> = {
[C in keyof T]: T[C] extends Required<T>[C] ? never : T[C];
};
declare module "react-router" {
interface RouteComponentProps<Params extends NoRequired<Params> }> {
params: Params;
}
}
// Using the Interface
import { RouteComponentProps } from "react-router";
// I don't want to extend RouteComponentProps<{ page: string }>, but I can.
export interface CRUDComponentProps
extends RouteComponentProps<{ page: string }> {
serverName: string;
clientName: string;
}
As you can see the type is accepted as the node modules declaration type instead of a user defined declaration type. There no other way of overriding it other than removing it manually from the the node_modules type file.
Checklist
My suggestion meets these guidelines:
- A way of force overriding a type (preferably an override.d.ts or an *.override.d.ts file)
- A way to sort the order in which declaration merging happens
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 global.d.ts của issue, các mẫu override.d.ts hoặc *.override.d.ts được đề xuất và ví dụ về declaration-merging của react-router. Xem xét cách các khai báo module được chọn và hợp nhất, sau đó xác định hành vi cần thiết cho các workspace override và thứ tự khai báo. Công việc được xem là hoàn tất khi có một thiết kế đã được thống nhất cùng coverage cho hành vi override đượ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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- 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
- 30/100