1
我想輸入一個函數,它在打字稿中取某些東西或沒有東西。我怎麼做?如何在打字稿中輸入參數爲「any」或「void」的函數?
我已經試過:
interface TestFn {
(props: any | void): string
}
const thing: TestFn = (props) => 'whoo';
thing('something'); // this line is fine
thing(); // this is not okay
噢。我的代碼中有可選的參數太大聲了。謝謝您的幫助。我會盡快接受答案! –