Answer the question
In order to leave comments, you need to log in
How to replace with interface?
there is a function
function test(a: number, b: string, c: () => void): void {
...
}
interface TestInterface {
a: number;
b: string;
c: () => void;
}
Answer the question
In order to leave comments, you need to log in
Use the Robur variant .
Why? Because in a general sense, what you want to automatically get is impossible, because. the order of the keys in the object (and interface) does not matter, i.e. there is no difference between:
interface TestInterface {
a: number;
b: string;
c: () => void;
}
andinterface TestInterface {
c: () => void;
a: number;
b: string;
}
and in function, obviously, has. function test(a: TestInterface['a'], b: TestInterface['b'], c: TestInterface['c']): void {
// ,,,
}
the common type for all function arguments (aka rest parameter type) is tuple .
so, in your case
, you need to pass it with three dots. the only thing is, if you pass the array directly as a literal, you will need to indicate that it understands that this is a tuple.
here's an example of what works and what doesn't in the playground .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question