flowtype - 如何为导出函数的包声明接口?
flowtype - How to declare an interface for a package that exports a function?
假设我有一个像 import AltContainer from 'alt-container';
这样的导入。您将如何为此设置 declaration?该文档显示了如何为导出函数的模块实现此目的,但没有针对此特定情况的示例。
在您的 libs
目录中的文件中放入类似这样的内容:
declare module 'alt-container' {
declare function hello(foo: string): number;
}
如果模块的导出本身就是一个函数,您可以从模块中声明一个名为 exports
的函数。
lib/mymodule.js:
declare module "mymodule" {
declare function exports(foo: string): void;
}
index.js
import f from "mymodule";
f(0); // error: number ~> string
假设我有一个像 import AltContainer from 'alt-container';
这样的导入。您将如何为此设置 declaration?该文档显示了如何为导出函数的模块实现此目的,但没有针对此特定情况的示例。
在您的 libs
目录中的文件中放入类似这样的内容:
declare module 'alt-container' {
declare function hello(foo: string): number;
}
如果模块的导出本身就是一个函数,您可以从模块中声明一个名为 exports
的函数。
lib/mymodule.js:
declare module "mymodule" {
declare function exports(foo: string): void;
}
index.js
import f from "mymodule";
f(0); // error: number ~> string