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: type error while esModuleInterop is true #3436

Merged
merged 5 commits into from
Feb 3, 2019
Merged

Conversation

whxaxes
Copy link
Member

@whxaxes whxaxes commented Jan 30, 2019

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

当 tsconfig.json 中配置 "esModuleInterop": true 后 tsc 编译的时候会报这个错

491:39 Type 'typeof Application' is not a constructor function type.
    489 |   }
    490 | 
  > 491 |   export class EggApplication extends KoaApplication { // tslint:disable-line
        |                                       ^
    492 |     /**
    493 |      * The current directory of application
    494 |      */

原因是 import KoaApplication 是这么写的

import * as KoaApplication from 'koa';

而 koa 中用的是 export = Application 这种 commonjs 的声明暴露方式,遇到 esModuleInterop 会有问题,所以改成针对这种 export 方式的,又需要用到默认 export 出来的类型的,都用 import XX = require('xxx') 的方式来兼容。

@codecov
Copy link

codecov bot commented Jan 31, 2019

Codecov Report

Merging #3436 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3436      +/-   ##
==========================================
- Coverage   99.78%   99.76%   -0.02%     
==========================================
  Files          32       29       -3     
  Lines         910      844      -66     
==========================================
- Hits          908      842      -66     
  Misses          2        2
Impacted Files Coverage Δ
lib/egg.js 100% <0%> (ø) ⬆️
...ps/master-worker-started/node_modules/egg/index.js 100% <0%> (ø) ⬆️
lib/core/messenger/index.js
lib/start.js
lib/core/messenger/ipc.js
lib/core/messenger/local.js
lib/core/messenger.js 100% <0%> (ø)

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 20ba463...736722a. Read the comment docs.

@whxaxes whxaxes mentioned this pull request Feb 3, 2019
4 tasks
@atian25
Copy link
Member

atian25 commented Feb 3, 2019

等单测跑完你就合并吧

@dead-horse dead-horse merged commit d79da17 into master Feb 3, 2019
@dead-horse dead-horse deleted the ts-esModuleInterop branch February 3, 2019 05:43
popomore pushed a commit that referenced this pull request Feb 3, 2019
fix: type error while esModuleInterop is true (#3436)
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.

None yet

3 participants