-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: MidwayRequestContainer 增加泛型标注 #407
Conversation
要不直接搞2.0里吧。。 |
Codecov Report
@@ Coverage Diff @@
## master #407 +/- ##
=======================================
Coverage 89.56% 89.56%
=======================================
Files 36 36
Lines 843 843
Branches 48 48
=======================================
Hits 755 755
Misses 78 78
Partials 10 10
Continue to review full report at Codecov.
|
这个功能应该和版本无关,merge 之后1.x和2.x都行吧 @czy88840616 |
也可以。。就是我要cherry-pick。。 |
@@ -43,7 +43,7 @@ export class MidwayRequestContainer extends MidwayContainer { | |||
} | |||
} | |||
|
|||
async getAsync<T>(identifier: any, args?: any) { | |||
async getAsync<T = any>(identifier: any, args?: any) :Promise<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- TypeScript 中 T 默认就是any,这里没有必要加吧
- 默认就是返回 T 类型的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从 typescript 3.5.0 开始默认是 unknown 类型的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认是 unknown,所以如果不加 T=any 的话,很多之前的老代码都可能会报错。 @kurten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any
既是 top 顶级类型也是 bottom 最下级类型,而 unknown
只是 bottom 最下级类型。
feat: MidwayRequestContainer 增加泛型标注 (#407)
(cherry picked from commit daee9d3)
Checklist
npm test
passesAffected core subsystem(s)
Description of change