flowtype - How to declare an interface for a package that exports a function?

Let's say I have an import like import AltContainer from 'alt-container';. How would you set up a declaration for that? The documentation shows how to achieve this for a module that exports functions but there's no example for this particular case.

Upvotes: 1

Views: 1408

Answers (2)

Sam Goldman
Sam Goldman

Reputation: 1446

If the exports of the module is itself a function, you can declare a function named exports from the module.

lib/mymodule.js:

declare module "mymodule" {
  declare function exports(foo: string): void;
}

index.js

import f from "mymodule";
f(0); // error: number ~> string

Upvotes: 4

danvk
danvk

Reputation: 16905

Put something like this in a file in your libs directory:

declare module 'alt-container' {
  declare function hello(foo: string): number;
}

Upvotes: -1

Related Questions