Ghojzilla
Ghojzilla

Reputation: 313

Unsure how to infer function parameter types

With the following code, how would I replace the anys 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.

Upvotes: 1

Views: 35

Answers (1)

ttquang1063750
ttquang1063750

Reputation: 863

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

Upvotes: 2

Related Questions