简体   繁体   中英

Unsure how to infer function parameter types

With the following code, how would I replace the any s if it is even possible. I would like to remove the warning from 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.

Use a generic type


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM