javascript - 如何在流中使用对象属性的类型?

标签 javascript flowtype

如何在流中使用对象属性的类型?例如

type A = {
  someproperty: string
}

// throws error
const b: A.someproperty = "hello"

最佳答案

您可以使用 $PropertyType<T,x> utility type .

type A = {
  someproperty: string
}

// this works fine
const b: $PropertyType<A, 'someproperty'> = "hello"

关于javascript - 如何在流中使用对象属性的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44924922/

相关文章:

Javascript getElementById() 适用于文本框,但不适用于单选按钮或下拉选择器

c# - 从 request.querystring 中删除字符

javascript - 如何为必须至少具有一个属性的对象定义流类型?

javascript - 递归函数的流注解

javascript - 具有所有动态键的流类型,但所有键的类型相同

javascript - React Native - React.createElement 不是函数

javascript - LESS 属性在 Firefox 中加载不一致

javascript - 如何更改 React 组件中的 CSS 高度?

javascript - 无法弄清楚为什么某些部分功能没有被覆盖,流程

javascript - JS 流 : What is the most clean and concise way to define an enum that is also treated like a type