type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Add `FunctionOverloads` type

Open andreww2012 opened this issue 2 months ago • 4 comments

Resolves https://github.com/sindresorhus/type-fest/issues/868 and resolves partially https://github.com/sindresorhus/type-fest/issues/585

andreww2012 avatar Oct 09 '25 13:10 andreww2012

I think https://github.com/microsoft/TypeScript/issues/14107 may be relevant. Maybe link to it in the doc comment.

sindresorhus avatar Oct 10 '25 02:10 sindresorhus

Thank you for the review!

I think microsoft/TypeScript#14107 may be relevant. Maybe link to it in the doc comment.

I'm not sure how I'd link this issue. I think https://github.com/microsoft/TypeScript/issues/32164 is actually more relevant (and the author of the trick I've used also left the same comment about the method of getting union of overloads), but I don't see additional value of including it the docs too.

andreww2012 avatar Oct 10 '25 19:10 andreww2012

I think https://github.com/microsoft/TypeScript/issues/32164 is actually more relevant (and the author of the trick I've used also left the same comment about the method of getting union of overloads), but I don't see additional value of including it the docs too.

It can be useful as context to the limitation.

sindresorhus avatar Oct 11 '25 00:10 sindresorhus

Mentioned the issue that this type addresses.

Also removed the limitation of losing readonly modifier if other parameters are present from the docs because actually this combination is completely useless in practice:

declare function foo(bar: string, ...baz: readonly number[]): void;
declare const array: number[];
foo('', ...array); // Allowed despite `array` not being readonly

andreww2012 avatar Oct 11 '25 10:10 andreww2012