簡體   English   中英

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

[英]Unsure how to infer function parameter types

使用以下代碼,如果可能的話,我將如何替換any 我想從 TS 中刪除警告“ Unexpected any. Specify a different type

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.

使用泛型類型


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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM