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

[lodash] fix _.has not to be inferred to never on or operator #69534

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions types/lodash/common/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ = require("../index");
// eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers
type GlobalPartial<T> = Partial<T>;
export const uniqueSymbol: unique symbol;
declare module "../index" {
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
type PartialObject<T> = GlobalPartial<T>;
Expand Down
3 changes: 2 additions & 1 deletion types/lodash/common/object.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ = require("../index");
import { uniqueSymbol } from "./common";
declare module "../index" {
interface LoDashStatic {
/**
Expand Down Expand Up @@ -1327,7 +1328,7 @@ declare module "../index" {
* _.has(other, 'a');
* // => false
*/
has<T, K extends PropertyName>(object: T, path: K): object is T & { [P in K]: P extends keyof T ? T[P] : Record<string, unknown> extends T ? T[keyof T] : unknown};
has<T, K extends PropertyName>(object: T, path: K): object is T & { [P in K]: P extends keyof T ? T[P] : Record<string, unknown> extends T ? T[keyof T] : unknown} & {[uniqueSymbol]: unknown};
has<T>(object: T, path: PropertyPath): boolean;
}
interface LoDashImplicitWrapper<TValue> {
Expand Down
6 changes: 6 additions & 0 deletions types/lodash/lodash-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5444,6 +5444,12 @@ fp.now(); // $ExpectType number
const result: { a: number | string } = record;
record; // $ExpectType Record<string, number | string>
}
const data = {
level: 1,
length: 1,
};
_.has(data, 'level') || !!data.length;

_(abcObject).has(""); // $ExpectType boolean
_(abcObject).has(42); // $ExpectType boolean
_(abcObject).has(["", 42]); // $ExpectType boolean
Expand Down