2017-08-30 52 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