Skip to content

Commit

Permalink
Generalize TypeScript declaration (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
azatoth and sindresorhus committed Dec 20, 2020
1 parent cde3c6f commit 66079d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.d.ts
Expand Up @@ -21,8 +21,10 @@ importFresh('./foo')();
importFresh('./foo')();
//=> 1
const foo = importFresh<typeof import('./foo')>('./foo');
```
*/
declare function importFresh(moduleId: string): unknown;
declare function importFresh<T>(moduleId: string): T;

export = importFresh;
7 changes: 7 additions & 0 deletions index.test-d.ts
@@ -1,5 +1,12 @@
import {expectType, expectError} from 'tsd';
import importFresh = require('.');
import path = require('path');

expectType<unknown>(importFresh('hello'));
expectError(importFresh());

expectType<(moduleId: string) => {}>(importFresh<(moduleId: string) => {}>('hello'));
expectType<path.PlatformPath>(importFresh<path.PlatformPath>('path'));

const foo = importFresh<path.PlatformPath>('path');
expectType<path.PlatformPath>(foo);

0 comments on commit 66079d9

Please sign in to comment.