Skip to content

Commit

Permalink
fix the optional problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Harris-Miller committed Jan 21, 2024
1 parent 2c718c5 commit dcbe597
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 0 additions & 3 deletions test/propEq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ type Obj = {

const obj = {} as Obj;

const literalVar = 'A';
let typedVar: 'A' | 'B' = 'A';

//
// literals
//
Expand Down
6 changes: 3 additions & 3 deletions types/propEq.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { WidenLiterals } from './util/tools';
// propEq(val)
export function propEq<T>(val: T): {
// propEq(val)(name)(obj)
<K extends PropertyKey>(name: K): <U extends Record<K, any>>(obj: T extends WidenLiterals<U[K]> ? U : never) => boolean;
<K extends PropertyKey>(name: K): <U extends Partial<Record<K, any>>>(obj: Required<U> extends Record<K, any> ? T extends WidenLiterals<U[K]> ? U : never : never) => boolean;
// propEq(val)(name, obj)
<K extends keyof U, U extends Record<PropertyKey, any>>(name: K, obj: T extends WidenLiterals<U[K]> ? U : never): boolean;
<K extends PropertyKey, U extends Partial<Record<K, any>>>(name: K, obj: Required<U> extends Record<K, any> ? T extends WidenLiterals<U[K]> ? U : never : never): boolean;
};
// propEq(val, name)(obj)
export function propEq<T, K extends PropertyKey>(val: T, name: K): <U extends Record<K, any>>(obj: T extends WidenLiterals<U[K]> ? U : never) => boolean;
export function propEq<T, K extends PropertyKey>(val: T, name: K): <U extends Partial<Record<K, any>>>(obj: Required<U> extends Record<K, any> ? T extends WidenLiterals<U[K]> ? U : never : never) => boolean;
// propEq(val, name, obj)
export function propEq<K extends keyof U, U>(val: U[K], name: K, obj: U): boolean;

0 comments on commit dcbe597

Please sign in to comment.