亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不確定如何推斷函數參數類型

不確定如何推斷函數參數類型

明月笑刀無情 2023-09-21 16:40:33
使用以下代碼,any如果可能的話,我將如何替換 s 。我想刪除 TS 中的警告“任何意外。指定不同的類型”interface Props {    isPrime: boolean;}interface Other {    isEdit: boolean;}type TFunc = (a: any, b: any) => any;const myFunc = (c: TFunc) => (a: any) => (b: any) => c(a, b);const funcA = myFunc((props: Props, other: Other) => {    // ..somecode}// Code to call the func A result ect.
查看完整描述

1 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

使用泛型類型

interface Props {

? isPrime: boolean;

}

interface Other {

? isEdit: boolean;

}

type TFunc<T, U> = (a: T, b: U) => any;

const myFunc = <T, U>(c: TFunc<T, U>) => (a: T) => (b: U) => c(a, b);


const funcA = myFunc<Props, Other>((props: Props, other: Other) => {

? // ..somecode

});


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號