Inconvenient types import / export
See original GitHub issueFirst and foremost: Great that you switched from Flow to TypeScript! Although, when switching from @types/cosmiconfig
to the types which are now provided by this package, I experienced the following issues:
No direct import for CosmiconfigResult
Currently when I want to declare a variable which will get the result from cosmiconfig.search()
, I need to do it like this:
import {cosmiconfig} from 'cosmiconfig';
import {CosmiconfigResult} from 'cosmiconfig/dist/types';
let result: CosmiconfigResult;
But I’d like to import it conveniently like this:
import {cosmiconfig, CosmiconfigResult} from 'cosmiconfig';
let result: CosmiconfigResult;
Unfortunately this is not possible since CosmiconfigResult
is not re-exported from the types
dir. I tried fixing it but since isolatedModules: true
is set in tsconfig.json
, re-exporting is disallowed:
src/index.ts:137:56 - error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
137 export { cosmiconfig, cosmiconfigSync, defaultLoaders, CosmiconfigResult };
No clear return type of cosmiconfig()
I have a class which adds cosmiconfig as a property and I have to define its type. Since cosmiconfig()
returns an object (and is especially excluded from needing a convenient return type), I need to declare it like this:
import {cosmiconfig} from 'cosmiconfig';
class MyClass {
private readonly cosmiconfig: ReturnType<typeof cosmiconfig>;
constructor() {
this.cosmiconfig = cosmiconfig('myconfig');
}
}
I’d rather like to be able to declare it like this:
import {cosmiconfig, Cosmiconfig} from 'cosmiconfig';
class MyClass {
private readonly cosmiconfig: Cosmiconfig;
constructor() {
this.cosmiconfig = cosmiconfig('myconfig');
}
}
Where Cosmiconfig
is an interface which describes the return value of cosmiconfig()
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I disagree.
ReturnType
is a Utility Type which IMO is a good fallback if you don’t have any interface on hand. The preferred way should be a clear interface. But that’s just my opinion. 🙂Closing as stale.