2017-08-30 51 views
1

如下代码中,我使用Element<*>JSX元件的类型。流动型JSX元件,怪异臭虫以元素<*>(星号)

type Prop = { 
    style?: StyleSheet.styles | Array<StyleSheet.styles>; 
    face: Element<*>; 

    disabled: boolean; 
    anotherProp: any; 
} 

Element<*>(星号)的使用是通过流动型编译提示。

enter image description here

但随后,Element<*>之后定义每一种类型的缺失。

enter image description here

如果我改变代码Element<any>,然后我喜欢的类型正确显示。

enter image description here

但键入any是不是我真正需要的。我能做些什么才能使它工作?

我用flowtype with vscode,但似乎误差为flowtype编译器(或flowtype vscode plugin),所以可能不会涉及到vscode本身。

+0

@zvona是的,我都尝试逗号和分号,他们似乎工作中同样的方式(但在这种情况下都不起作用) – Val

回答

1

目前与导致某些类型的,尤其是那些使用*,尽管此编辑器集成的问题,注意类型实际上是正确的,并根据会检查你写的东西,即使它打印出错误的IDE。

例如,下面的代码失败,一个类型的错误,而如果any类型实际上是用它会通过:

type thingy = { 
    style: number, 
    stuff: Array<*>, 
    things: string 
} 

let t: thingy = { 
    style: 19, 
    stuff: 2, 
    things: "what" 
} 
+1

谢谢。你有关于这个*编辑器问题与某些类型的链接*? – Val

+0

大约有类型的打印几个问题:https://github.com/facebook/flow/issues?q=is%3Aopen+is%3Aissue+label%3Atype-at-pos这是此一例。 – Adam

+0

我用'type-at-pos'命令几乎在每一个类型上都得到了'(未知)'... ouch。即使是一个非常简单的例子:'type Prop = 1 | 2'。但类型的行号是正确的。 – Val