Skip to content

Commit

Permalink
Add support for ESM - fixes #95
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed May 10, 2021
1 parent 0e9228a commit d2284a1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions source/test/fixtures/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const one: {
(foo: string, bar: string): string;
(foo: number, bar: number): number;
<T extends string>(foo: T, bar: T): string;
};

export = one;
3 changes: 3 additions & 0 deletions source/test/fixtures/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const one = (foo, bar) => foo + bar;

export default one;
4 changes: 4 additions & 0 deletions source/test/fixtures/esm/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from '../../../..';
import one from './index.js';

expectType<string>(one('foo', 'bar'));
5 changes: 5 additions & 0 deletions source/test/fixtures/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "foo",
"type": "module",
"exports": "./index.js"
}
8 changes: 8 additions & 0 deletions source/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')});

Expand Down

0 comments on commit d2284a1

Please sign in to comment.