Skip to content

Commit

Permalink
fix: type error while esModuleInterop is true (#3436)
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes authored and dead-horse committed Feb 3, 2019
1 parent 20ba463 commit d79da17
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 5 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as accepts from 'accepts';
import * as KoaApplication from 'koa';
import * as KoaRouter from 'koa-router';
import accepts = require('accepts');
import KoaApplication = require('koa');
import KoaRouter = require('koa-router');
import { EventEmitter } from 'events'
import { Readable } from 'stream';
import { Socket } from 'net';
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/apps/app-ts-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
node_modules
15 changes: 15 additions & 0 deletions test/fixtures/apps/app-ts-esm/app/controller/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Controller, RequestObjectBody } from 'egg';

// add user controller and service
declare module 'egg' {
interface IController {
foo: FooController;
}
}

// controller
export default class FooController extends Controller {
async index() {
this.ctx.body = 'ok';
}
}
5 changes: 5 additions & 0 deletions test/fixtures/apps/app-ts-esm/app/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Application } from 'egg';

export default (app: Application) => {
app.get('/foo', app.controller.foo.index);
}
4 changes: 4 additions & 0 deletions test/fixtures/apps/app-ts-esm/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
keys: 'foo',
serverTimeout: 2 * 60 * 1000,
}
4 changes: 4 additions & 0 deletions test/fixtures/apps/app-ts-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "app-ts",
"version": "1.0.0"
}
15 changes: 15 additions & 0 deletions test/fixtures/apps/app-ts-esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2017",
"baseUrl": ".",
"paths": {
"egg": [
"../../../../index"
]
},
"module": "commonjs",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
}
}
21 changes: 19 additions & 2 deletions test/ts/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');
const request = require('supertest');
const mm = require('egg-mock');
const runscript = require('runscript');
const coffee = require('coffee');
const path = require('path');
const fs = require('fs');
const mkdirp = require('mz-modules/mkdirp');
Expand All @@ -13,7 +13,14 @@ const baseDir = path.join(__dirname, '../fixtures/apps/app-ts');

describe('test/ts/index.test.js', () => {
before(async () => {
await runscript(`tsc -p ${baseDir}/tsconfig.json`, { cwd: baseDir });
await coffee.fork(
require.resolve('typescript/bin/tsc'),
[ '-p', path.resolve(__dirname, '../fixtures/apps/app-ts/tsconfig.json') ]
)
// .debug()
.expect('code', 0)
.end();

const dest = path.join(baseDir, 'node_modules/egg');
await rimraf(dest);
await mkdirp(path.dirname(dest));
Expand Down Expand Up @@ -55,5 +62,15 @@ describe('test/ts/index.test.js', () => {
.expect({ env: 'unittest' })
.end(done);
});

it('should compile with esModuleInterop without error', async () => {
await coffee.fork(
require.resolve('typescript/bin/tsc'),
[ '-p', path.resolve(__dirname, '../fixtures/apps/app-ts-esm/tsconfig.json') ]
)
// .debug()
.expect('code', 0)
.end();
});
});
});

0 comments on commit d79da17

Please sign in to comment.