Skip to content

ts 2.3 -> 2.4 type predicate regression #19676

Closed

Description

@MarenkovIgor

TypeScript Version: 2.4.1

testFindTypeGuard.ts:

let el: Element;

const nodes: Node[] = [];

const result = nodes.find((n): n is HTMLFontElement => n.nodeName === "FONT");

el = result;

my.d.ts:

interface Array<T> {
    find<U extends T>(predicate: (value: T, index: number, obj: Array<T>) => value is U): U | undefined;
}

Expected behavior:
Compiles fine (true for ts 2.1, 2.3)

Actual behavior: error TS2322: Build:Type 'Node' is not assignable to type 'Element'.
(tested with ts 2.4.1 and 2.7.0-dev.20171101)

Activity

  1. fictitious commented on Nov 2, 2017

    @fictitious

    This appears to be the commit that changed inferred type for find from HTMLFontElement to Node

  2. MarenkovIgor commented on Nov 2, 2017

    @MarenkovIgor
    Author

    fictitious, commit diff is too complex for me. Any suggestion, how fix the code?

  3. ahejlsberg commented on Nov 2, 2017

    @ahejlsberg
    Member

    Looks like a duplicate of #17451. Andy (Andrewkraft) (@Andy-MS) can you verify?

  4. typescript-bot commented on Nov 17, 2017

    @typescript-bot
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  5. locked and limited conversation to collaborators on Jun 14, 2018
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

    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