diff --git a/source/lib/config.ts b/source/lib/config.ts index 80e1f5f9..d106b422 100644 --- a/source/lib/config.ts +++ b/source/lib/config.ts @@ -37,6 +37,7 @@ export default (pkg: {tsd?: RawConfig}, cwd: string): Config => { lib: ['lib.es2017.d.ts'], module: ModuleKind.CommonJS, target: ScriptTarget.ES2017, + esModuleInterop: true, ...tsConfigCompilerOptions, ...packageJsonCompilerOptions, moduleResolution: ModuleResolutionKind.NodeJs, diff --git a/source/test/fixtures/esm/index.d.ts b/source/test/fixtures/esm/index.d.ts new file mode 100644 index 00000000..110b2b75 --- /dev/null +++ b/source/test/fixtures/esm/index.d.ts @@ -0,0 +1,7 @@ +declare const one: { + (foo: string, bar: string): string; + (foo: number, bar: number): number; + (foo: T, bar: T): string; +}; + +export = one; diff --git a/source/test/fixtures/esm/index.js b/source/test/fixtures/esm/index.js new file mode 100644 index 00000000..0d28b4c1 --- /dev/null +++ b/source/test/fixtures/esm/index.js @@ -0,0 +1,3 @@ +const one = (foo, bar) => foo + bar; + +export default one; diff --git a/source/test/fixtures/esm/index.test-d.ts b/source/test/fixtures/esm/index.test-d.ts new file mode 100644 index 00000000..67eb5ed0 --- /dev/null +++ b/source/test/fixtures/esm/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from '../../../..'; +import one from './index.js'; + +expectType(one('foo', 'bar')); diff --git a/source/test/fixtures/esm/package.json b/source/test/fixtures/esm/package.json new file mode 100644 index 00000000..75bc3f28 --- /dev/null +++ b/source/test/fixtures/esm/package.json @@ -0,0 +1,5 @@ +{ + "name": "foo", + "type": "module", + "exports": "./index.js" +} diff --git a/source/test/test.ts b/source/test/test.ts index f5afee63..d8d7697f 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -103,6 +103,14 @@ test('allow specifying a lib in tsconfig.json', async t => { verify(t, diagnostics, []); }); +test('add support for esm with esModuleInterop', async t => { + const diagnostics = await tsd({ + cwd: path.join(__dirname, 'fixtures/esm') + }); + + verify(t, diagnostics, []); +}); + test('a lib option in package.json overrdides a lib option in tsconfig.json', async t => { const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/lib-config/lib-from-package-json-overrides-tsconfig-json')});