Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Flow键入默认导出? 如何使用Flow键入默认导出?Flow有实现这一点的方法吗? 预期结果: 可接受的备选方案:_Javascript_Ecmascript 6_Flowtype - Fatal编程技术网

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)