我有一个看起来像这样的流类型的对象。我通过在 Vscode 中悬停检查了 require
函数是什么。但不确定从这里访问它?我想知道我是否需要像 flow-typed 这样的东西.但是在那里找不到。我输入的是否正确?
// @flow
const backgroundImage = require('./myBg.jpeg')
type configType = {
backgroundImage: string | NodeRequire
}
const config = {
backgroundImage
}
最佳答案
如果您使用 webpack 和 url loader,图像通常是一个字符串。您可以使用 name_mapper.extension
option of flow自动输入所有 jpeg
(如果扩展正则表达式,还有其他文件)文件导入为字符串:
# .flowconfig
[options]
module.name_mapper.extension='jpeg' -> '<PROJECT_ROOT>/ImageFlowStub.js.flow'
然后在您的项目根目录中创建 ImageFlowStub.js.flow
文件(或其他任何地方并调整 .flowconfig
中的路径:
/* @flow */
declare export default string;
另见这个问题:Flow “Required module not found” when importing a CSS file
关于javascript - 如何流式输入 'require(' ')' 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56646441/