Skip to content

fix: Compat for ts type error #485

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

Merged
merged 1 commit into from
Feb 24, 2021
Merged

fix: Compat for ts type error #485

merged 1 commit into from
Feb 24, 2021

Conversation

s524797336
Copy link
Contributor

fix: #484

@codecov
Copy link

codecov bot commented Feb 2, 2021

Codecov Report

Merging #485 (b48395c) into master (05d9833) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #485   +/-   ##
=======================================
  Coverage   40.00%   40.00%           
=======================================
  Files           7        7           
  Lines         455      455           
  Branches       98       99    +1     
=======================================
  Hits          182      182           
  Misses        271      271           
  Partials        2        2           
Impacted Files Coverage Δ
src/api.ts 62.85% <100.00%> (ø)
src/pool.ts 95.45% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05d9833...afdb896. Read the comment docs.

Copy link
Collaborator

@yinxulai yinxulai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常感谢您的建议,有一些小问题

src/pool.ts Outdated
@@ -2,7 +2,7 @@ export type RunTask<T> = (...args: T[]) => Promise<void>

export interface QueueContent<T> {
task: T
resolve: () => void
resolve: (value?: unknown) => void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实际上,这个问题导致的原因是 Poolenqueue 方法在向 queue 添加任务时,创建 QueueContent 传递了类型不正确的 resolve导致的,而非 QueueContent 本身的类型问题,所以更好的办法应该是修复 enqueue 的内部实现

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

推荐在 new Promise 时指定范型来使的 resolve 的类型推导正确
image

Copy link
Collaborator

@yinxulai yinxulai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@yinxulai yinxulai merged commit d1792bd into qiniu:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

和 typescript 4.1.3一起用时报ts 类型错误
3 participants