Closed ikornienko closed 2 years ago
I think a better approach would be a function type override
function initials(nameOrNames: string, options?: Options): string;
function initials(nameOrNames: string[], options?: Options): string[];
Not sure if that's the exact syntaxt, but I think that would work better and does not require a type parameter
Function overload would be ideal! While not being a TS expert, I wasn't aware that TS supports it, but it's indeed there (docs). Definitely better to make those two function signatures defined explicitly.
:tada: This issue has been resolved in version 3.1.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Problem
Currently it has
which adds additional pain to the user who has to deal with the fact that
won't compile, besides documentation explicitly saying that the result will be
JD
(i.e.string
).Possible way to improve typings
In this case if array is passed as a first argument, then function returns an array. And if it's just a string then its return type also is just a string.