【发布时间】:2023-04-04 16:28:02
【问题描述】:
如何使用 Flow 键入默认导出? Flow 有办法做到这一点吗?
期望的结果:
// index.js
type complexThing = {
a: string
}
type Thing = {
x: number,
y: boolean,
z: complexThing
}
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing // this says my default export is a Thing
可接受的替代方案:
或者,我不介意内联输入每个对象属性,但我认为这在语法上是不可能的:
export default {
// I don't know how to add type signatures here
x: 0, // number
y: true, // boolean
z: {a: 'hello'} // complexThing
}
不是我想要的:
我不想要做的是存储一个变量,只是为了流式输入它:
// index.js
type complexThing = {
a: string
}
type Thing = {
x: number,
y: boolean,
z: complexThing
}
const myThing: Thing = {
x: 0,
y: true,
z: {a: 'hello'}
}
export default myThing
【问题讨论】:
标签: javascript ecmascript-6 flowtype