Skip to content

Type inference with reduce functions #36225

Closed

Description

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

Activity

  1. RyanCavanaugh commented on Feb 1, 2020

    @RyanCavanaugh
    Member

    Please add to our suite at #36554

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions