-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declare default export among other exports #1806
Comments
Unfortunately this is a shortcoming of our The plan to address this is to add |
That's great news that you're starting working on this. Thank you! In the meantime, is there a way to add type info somehow for such module? I'm experimenting with using |
@rpominov: If there is no way for you to change the upstream module directly right now then the only 2 workarounds I can think of are:
declare module 'my-module' {
declare module.exports: {
default: React.Component,
foo: string,
};
}
export {default as component, foo} from "my-module";
declare module 'my-module' {
declare var component: React.Component;
declare var foo: string;
} |
Thanks! Can't check at the moment, but I think both methods should work great in my case 👍 |
Ok, this has been fixed as of v0.28. You can now do the following: declare module "my-module" {
declare export default React.Component;
declare export var foo: string;
} import DefaultReactComponent from "my-module";
import {foo} from "my-module"; |
Is there any difference between these two? declare module "my-module" {
declare export var foo: string;
} declare module "my-module" {
declare var foo: string;
} |
Is this supposed to work ? I tried on 0.30.0. But not of below works and I'm getting errors:
|
You should do it like this (only one line needed): // @flow
declare module "my-modules" {
declare export default string;
} // @flow
import a from 'my-modules'
(a: number)
|
To complete the answers above, you can do one of the following form to define your modules // usage:
// import foo from 'some-module'
declare module 'some-module' {
declare type Foo = {/*...*/}
declare export default Foo
}
// usage:
// import myFunc from 'some-module'
declare module 'some-module' {
declare export default () => void
}
// usage:
// import { foo } from 'some-module'
declare module 'some-module' {
declare type Foo = {/*...*/}
declare export var foo: FooType
}
// usage:
// import Foo from 'some-module'
declare module 'some-module' {
declare class Foo {}
declare export default typeof Foo
} |
One more that seems to be even compatible with eslint:
|
@tomitrescak: |
I'm new to flow but just an FYI related to this issue the import EventEmitter from 'events'
//or
import {EventEmitter} from 'events' got it to work with suggestions above declare module "events" {
// TODO: See the comment above the events$EventEmitter declaration
declare class EventEmitter {
static EventEmitter: typeof EventEmitter;
// deprecated
static listenerCount(emitter: events$EventEmitter, event: string): number;
addListener(event: string, listener: Function): events$EventEmitter;
emit(event: string, ...args:Array<any>): boolean;
listeners(event: string): Array<Function>;
listenerCount(event: string): number;
on(event: string, listener: Function): events$EventEmitter;
once(event: string, listener: Function): events$EventEmitter;
removeAllListeners(event?: string): events$EventEmitter;
removeListener(event: string, listener: Function): events$EventEmitter;
setMaxListeners(n: number): void;
getMaxListeners(): number;
}
declare export var EventEmitter: typeof EventEmitter
declare export default typeof EventEmitter
} hopefully that saves someone some time |
I get a parse error on: declare export var ... |
@peterhal: Are you writing it like this? |
@jeffmo I'm also getting the parse error. Might have something to do with the babel parser for eslint? |
For those using
|
Is there a way to import a default type from a CommonJS module? I'm trying to do declare module 'superagent' {
declare class Superagent {
(method: string, url: string): Request;
get(url: string): Request;
head(url: string): Request;
put(url: string): Request;
post(url: string): Request;
delete(url: string): Request;
patch(url: string): Request;
options(url: string): Request;
trace(url: string): Request;
}
declare module.exports: Superagent;
} but then |
How would you export a variable with a hyphen with the |
Suppose there is an npm module like this:
And I want to write a declaration file for this module. If it only has the
default
export I would write something like this:If it doesn't have the
default
export, I would do:But in combination this doesn't work:
The text was updated successfully, but these errors were encountered: