[英]How to infer return type of function with provided arguments?
與https://github.com/Microsoft/TypeScript/issues/26043相關
const f = <T extends any>(a: T) => a;
// How to implement ReturnTypeWithArguments ???
type r = ReturnTypeWithArguments<typeof f, number> // number
在類型注釋中沒有將類型參數應用於通用函數的語法。 我們可以聲明一個函數,在其中調用通用函數(我們將不使用)並獲取該函數的返回值:
const f = <T extends any>(a: T) => a;
const fForNumber = () => f(0)
type r = ReturnType<typeof fForNumber> // number
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.