Skip to content

Empty tuple not inferred from rest parameters of a generic array type #38770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fasttime opened this issue May 25, 2020 · 2 comments
Closed

Empty tuple not inferred from rest parameters of a generic array type #38770

fasttime opened this issue May 25, 2020 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@fasttime
Copy link

TypeScript Version: 3.9.3

Search Terms: generic rest parameters empty tuple

Code

declare function requireAtLeast1Arg<T extends any[]>(...args: T extends [] ? never : T);

requireAtLeast1Arg();

Expected behavior: The code above should trigger the infamous compiler error 2345 as it used to do in TypeScript <= 3.8.

Actual behavior: The code compiles in current TypeScript 3.9.3.

I couldn't find a release note about the new behavior, so I'm assuming this was a kind of unintended breaking change.

Playground Link:

@ahejlsberg
Copy link
Member

This is an intended change, see #35438. A better way to require at least one argument is

declare function requireAtLeast1Arg<T extends [any, ...any[]]>(...args: T): void;

requireAtLeast1Arg();  // Error
requireAtLeast1Arg(42);
requireAtLeast1Arg(42, 'hello');

This also produces a much better error message.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label May 25, 2020
@fasttime
Copy link
Author

I see, thanks. Missed that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants