microsoft / microsoft/TypeScript
Support `@deprecated` marker on namespace aliases
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
"@deprecated", "deprecated", "namespace", "namespace alias"
### ✅ Viability Checklist
- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
### ⭐ Suggestion
Note: Marking this as a feature request, very well might be a bug. It's one of those that are probably up for interpretation?
---
I'd like the ability to annotate namespace aliases with `@deprecated`. At the moment you'd need to mark the referenced type as deprecated, which often isn't viable.
Here's a little example:
```ts
// @filename: example.d.ts
export type Bar = string | number;
/** @deprecated */
export type Baz = string | number;
// @filename: foo.ts
import * as example from './example';
declare namespace JSX {
/** @deprecated */
export type Foo = string | number;
/** @deprecated */
export import Bar = example.Bar;
export import Baz = example.Baz;
}
let x: JSX.Foo; // Marked as deprecated
let y: JSX.Bar; // Not marked as deprecated (but should be)
let z: JSX.Baz; // Marked as deprecated
```
[TypeScript Playground Link](https://www.typescriptlang.org/play/?jsx=0&multiFile=true#code/PTAEAEDMEsBsFMB2BDAtvAXKeAPNAHBAOgBMiAXAZwChd8B7AJ3NHIE995QAhZR0ALyhK5RtEQBzUAB9QiAK6oARvEYBuatWAAqbRBLx8jeAGNk5eCVDbgtHA2asOXXgC9Bw0eKmyFy1RqaIBAwCCjoWJD09BQ00KgOLHrIlNh4CQigkIz0qKAA5ETAuAQI+YEGJrB8XOHwlPjIJlwAUgDKABqgAN7UAJA6euAGRqbmlta2fXRMLOycoABi0R4iYpIycooq6poDuvqGxmYWVjb9M47xiTx8HiUZ8ES8uxf2s6DXH2736YRPbg0AF9NAgWDgsO0OkRlvQNGDQGxIZ1nnx4fAWK5kdDAUA)
### 📃 Motivating Example
Allows developers to mark namespace aliases as deprecated, giving downstream users more warning when those aliases will go away.
### 💻 Use Cases
1. What do you want to use this for?
[preact](https://github.com/preactjs/preact) has long since loaded up the JSX namespace with unrelated types... shouldn't have, but did. We're looking to get rid of this in our next major and to help folks migrate we wanted to extract the types to the `preact` namespace and re-export them as aliases through the `JSX` namespace. This will avoid any breaking changes in the current version and allow folks to keep compatibility with v10 and the upcoming v11.
Unfortunately, however, we can't mark this usage as deprecated which is a shame.
2. What shortcomings exist with current approaches?
Just doesn't work. End users get no warning that the namespace alias is deprecated.
3. What workarounds are you using in the meantime?
Just duplicated all the types. Instead of extracted types that are consumed both as direct exports and namespace aliases, we've had to make copies. Those in the namespace get the deprecation comment, those outside do not.
It's pretty fragile obviously, any change to one now has to be reflected to the same interface in another file.
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 trong issue và theo dõi cách trạng thái không còn được khuyến nghị được báo cáo cho các thành viên namespace và bí danh kiểu. Thêm kiểm thử hồi quy cho `export import Bar = example.Bar` để `JSX.Bar` được đánh dấu là không còn được khuyến nghị, trong khi hành vi hiện tại của `JSX.Baz` vẫn không thay đổi. Được xem là hoàn tất khi các bí danh namespace tạo ra cảnh báo không còn được khuyến nghị như mong đợi mà không thay đổi đầu ra JavaScript.
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
- 35/100