2016-09-22 34 views

回答

2

您可以使用可選的參數:

interface TestFn { 
    (props?: any): string  // <- parameters is marked as optional 
} 

const thing: TestFn = (props) => 'whoo'; 
thing('something'); // this line is fine 
thing(); // this line is fine as well 

參數props標有?,這意味着該參數是可選。有關可選參數的更多信息,請參見TypeScript documentation,部分可選參數和默認參數

+0

噢。我的代碼中有可選的參數太大聲了。謝謝您的幫助。我會盡快接受答案! –

相關問題