2016-07-01 29 views
1

我有以下類型的別名:如何註釋一個對象中屬性的函數?

type TestType = { 
    critical: string, 
    failProps: Object, 
    successProps: ?Object, 
    test: Function, 
}; 

我想更具體與test。該功能應該是這樣的簽名:

function (value: string): boolean { /* ... */ } 

如何表明test應該採取一個字符串參數並返回一個布爾值?

回答

5

您可以使用下面的語法:

type TestType = { 
    critical: string, 
    failProps: Object, 
    successProps: ?Object, 
    test: (value: string) => boolean, 
}; 

...或者,如果你想重用的功能型別的地方:

type functionType = (value: string) => boolean 
type TestType = { 
    critical: string, 
    failProps: Object, 
    successProps: ?Object, 
    test: functionType, 
}; 
相關問題