Skip to content
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

Type inference with reduce functions #36225

Closed
falsandtru opened this issue Jan 16, 2020 · 1 comment
Closed

Type inference with reduce functions #36225

falsandtru opened this issue Jan 16, 2020 · 1 comment

Comments

@falsandtru
Copy link
Contributor

Type of array elements shouldn't affect type inference in this case.

TypeScript Version: 3.7.x-dev.20200115

Search Terms:

Code

([] as any[]).reduce(() => 0, 0); // any
([] as unknown[]).reduce(() => 0, 0); // unknown
([] as never[]).reduce(() => 0, 0); // number

Expected behavior:

([] as any[]).reduce(() => 0, 0); // number
([] as unknown[]).reduce(() => 0, 0); // number
([] as never[]).reduce(() => 0, 0); // never or number

Actual behavior:

([] as any[]).reduce(() => 0, 0); // any
([] as unknown[]).reduce(() => 0, 0); // unknown
([] as never[]).reduce(() => 0, 0); // number

Playground Link: https://www.typescriptlang.org/play/?target=99&ts=3.8.0-dev.20200115&ssl=1&ssc=1&pln=3&pc=46#code/BQbQugBAhgztB2BPcBKAdAJwKYBMCuAxlsMChALwB8EADADS0oDcEA9KwogFCiSwR54Aa3gB7AO7xUmXIWKkK1eoxbsBwsZJ7hoceFgBuWDNOz4iJMlVoMazNh3h4AtgCNjQA

Related Issues: #25454

@RyanCavanaugh
Copy link
Member

Please add to our suite at #36554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants