Skip to content

Commit

Permalink
Catch missing imports - fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Jul 6, 2019
1 parent 1e373a6 commit 82e2f4c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default (pkg: {tsd?: RawConfig}, cwd: string): Config => {
target: ScriptTarget.ES2017,
...tsConfigCompilerOptions,
...packageJsonCompilerOptions,
moduleResolution: ModuleResolutionKind.NodeJs
moduleResolution: ModuleResolutionKind.NodeJs,
skipLibCheck: false
}
};
};
Expand Down
4 changes: 4 additions & 0 deletions source/test/fixtures/missing-import/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type LiteralUnion<
LiteralType extends BaseType,
BaseType extends Primitive
> = LiteralType | (BaseType & {_?: never});
1 change: 1 addition & 0 deletions source/test/fixtures/missing-import/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Nothing here
8 changes: 8 additions & 0 deletions source/test/fixtures/missing-import/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {expectType} from '../../..';
import {LiteralUnion} from '.';

type Pet = LiteralUnion<'dog' | 'cat', string>;

expectType<Pet>('dog');
expectType<Pet>('cat');
expectType<Pet>('unicorn');
3 changes: 3 additions & 0 deletions source/test/fixtures/missing-import/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "foo"
}
11 changes: 11 additions & 0 deletions source/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,14 @@ test('expectError for values', async t => {
t.true(diagnostics[0].message === 'Expected an error, but found none.');
t.true(diagnostics[0].severity === 'error');
});

test('missing import', async t => {
const diagnostics = await m({cwd: path.join(__dirname, 'fixtures/missing-import')});

t.true(diagnostics.length === 1);

t.true(diagnostics[0].column === 18);
t.true(diagnostics[0].line === 3);
t.true(diagnostics[0].message === 'Cannot find name \'Primitive\'.');
t.true(diagnostics[0].severity === 'error');
});

0 comments on commit 82e2f4c

Please sign in to comment.