Skip to content

#47069 breaks narrowing in @types/has and @types/lodash #47940

Closed
@sandersn

Description

@sandersn
declare function hasOwnProperty<P extends PropertyKey>(target: {}, property: P): target is { [K in P]: unknown };
declare const arrayLikeOrIterable: ArrayLike<any> | Iterable<any>;
if (hasOwnProperty(arrayLikeOrIterable, 'length')) {
    arrayLikeOrIterable; // $ExpectType ArrayLike<any>
}

Expected: arrayLikeOrIterable narrows to ArrayLike<any>
Actual: It doesn't, so instead the compiler intersects the declared type with { length: unknown }.

Broken by #47069

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions