Skip to content
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

fix: context declaration not works #3329

Merged
1 commit merged into from
Dec 19, 2018
Merged

fix: context declaration not works #3329

1 commit merged into from
Dec 19, 2018

Conversation

whxaxes
Copy link
Member

@whxaxes whxaxes commented Dec 19, 2018

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

原来 egg 的 context 声明是继承自 koa.Context 的,但是 egg 里的 context 中的部分属性 cookie 跟 koa 里的不是同一个,因此会产生类型不兼容 ( 在 skipLibCheck 为 false 的情况下跑 tsc 会报错 )。

在原来的解决方案中,是通过 RemoveSpecProp 这个工具类型将 koa.Context 中的 cookie 属性删掉再继承,但是最近 koa 的声明发了个版本在 context 声明上加了 [key: string]: any ,加了这个声明后就导致 keyof koa.Context 拿到的类型就错了,导致现在拿不到 koa.Context 里的声明。

我想到的解决方案是直接用 koa 内部的 BaseContext 类型,然后将 req 这些在 koa.Context 中的属性在 Context 中重新写一遍,以此来解决类型兼容问题。

#2958 (comment)

@whxaxes whxaxes changed the title fix: fix context declaration not works fix: context declaration not works Dec 19, 2018
@codecov
Copy link

codecov bot commented Dec 19, 2018

Codecov Report

Merging #3329 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3329   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          29       29           
  Lines         844      844           
=======================================
  Hits          842      842           
  Misses          2        2

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 ef47a27...7a34519. Read the comment docs.

@ghost ghost merged commit f312db7 into master Dec 19, 2018
@ghost ghost deleted the fix-context-d-ts branch December 19, 2018 12:53
popomore pushed a commit that referenced this pull request Dec 19, 2018
fix: fix context declaration not works (#3329)

Due to the change of Koa, we have to rewrite all the attributes based on koa.Context.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants