fix: context declaration not works #3329
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
npm test
passesAffected 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)