In many cases, I have a function that accepts many strings:
export const acceptsManyStrings = (one: string, two: string, three: string) => {
return one.slice(0,1) + two.slice(0,2) + three.slice(0,3);
}
because from a type perspective, the arguments are interchangeable, I may get the order wrong, pass two instead of one, or whatever.
Is there some way I could type each of the arguments somehow?
The only way I can think of is a dumb way, something like this:
export interface OneStr {
one: string
}
export interface TwoStr {
two: string
}
export interface ThreeStr {
three: string
}
and then use it like so:
export const acceptsManyStrings = (one: OneStr, two: TwoStr, three: ThreeStr) => {
return one.one.slice(0,1) + two.two.slice(0,2) + three.three.slice(0,3);
}
but that solution is pretty suboptimal for the obvious reasons. Any ideas?