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

ts 2.3 -> 2.4 type predicate regression #19676

Closed
MarenkovIgor opened this issue Nov 2, 2017 · 4 comments
Closed

ts 2.3 -> 2.4 type predicate regression #19676

MarenkovIgor opened this issue Nov 2, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@MarenkovIgor
Copy link

MarenkovIgor commented Nov 2, 2017

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)

@fictitious
Copy link

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

@MarenkovIgor
Copy link
Author

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

@ahejlsberg
Copy link
Member

Looks like a duplicate of #17451. @andy-ms can you verify?

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 2, 2017
@typescript-bot
Copy link
Collaborator

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

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants