Skip to content

Array.includes type is too narrow #26255

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 2.9.2

Search Terms: array includes es2016 widen

Code

Array.includes should allow the searchElement param to be a subtype of the array element type, e.g.

type A = 'foo' | 'bar' | 'baz'
type ASub = Extract<A, 'foo' | 'bar'>;
declare const aSubs: ASub[];
declare const a: A;
/*
Argument of type 'A' is not assignable to parameter of type '"foo" | "bar"'.
  Type '"baz"' is not assignable to type '"foo" | "bar"'.
*/
aSubs.includes(a);

Expected behavior:

No error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions