Javascript 如何使用Flow键入默认导出? 如何使用Flow键入默认导出?Flow有实现这一点的方法吗? 预期结果: 可接受的备选方案:
或者,我不介意内联键入每个对象属性,但我认为这在语法上是不可能的:Javascript 如何使用Flow键入默认导出? 如何使用Flow键入默认导出?Flow有实现这一点的方法吗? 预期结果: 可接受的备选方案:,javascript,ecmascript-6,flowtype,Javascript,Ecmascript 6,Flowtype,或者,我不介意内联键入每个对象属性,但我认为这在语法上是不可能的: 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: strin
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
你正在做一个测试,因此你需要在对象周围使用paren,例如change
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing
到
啊哈,是的,我现在明白了<代码>导出默认值{}是一个表达式,因此它需要类型转换来捕获类型签名。通过对象文字内联输入对象属性也可以使用同样的方法:
export default{x:(0:number)}
谢谢!
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing
export default ({
x: 0,
y: true,
z: {a: 'hello'}
} : Thing)