簡體   English   中英

流:使用泛型類型的可選道具

[英]Flow: optional prop that uses generic types

我有一個React組件,它具有一個名為showModal的功能道具。 我已經在其他地方使用泛型類型注釋了此函數,但是在這里,我希望它成為可選的道具。 通常,我使用func?: () => void做到這一點,但是這種語法在這種情況下不起作用(無論將?放在何處,都會出現Parsing error ):

type props = {
  showModal<T>(T => React$Node, T): void,
}

如何指定showModal是可選的? 我已經瀏覽了有關Flow的文檔,但找不到與此問題相關的任何內容。

您需要調整函數表達式。 流嘗試鏈接

type Props = {
  showModal?: <T>(T => React$Node, T) => void,
}

const foo: Props = {
  showModal: (a, b) => undefined
}

const bar: Props = {
  showModal: undefined
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM