Skip to content

Commit f17c02c

Browse files
committed
Fix objectChainable type in patterns.ts and Pattern.ts
1 parent 1831e29 commit f17c02c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/patterns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ const emptyObject = <input>(): GuardExcludeP<input, object, never> => when(
11381138

11391139
const objectChainable = <pattern extends Matcher<any, any, any, any, any>>(
11401140
pattern: pattern
1141-
): ObjectChainable<pattern> =>
1141+
): ObjectChainable<pattern> =>
11421142
Object.assign(chainable(pattern), {
11431143
empty: () => chainable(intersection(pattern, emptyObject())),
11441144
}) as any;
@@ -1153,4 +1153,4 @@ const objectChainable = <pattern extends Matcher<any, any, any, any, any>>(
11531153
* match(value)
11541154
* .with(P.object.empty(), () => 'will match on empty objects')
11551155
**/
1156-
export const object: ObjectChainable<any> = objectChainable(when(isObject));
1156+
export const object: ObjectChainable<GuardP<unknown, object>> = objectChainable(when(isObject));

src/types/Pattern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ export type ObjectChainable<
677677
* .with(P.object.empty(), () => 'empty object')
678678
*/
679679
empty<input>(): Chainable<
680-
ObjectP<input, Record<string, never>>,
680+
GuardExcludeP<input, {}, never>,
681681
omitted | 'empty'
682-
>;
682+
>;
683683
},
684684
omitted
685685
>;

tests/object.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('Object', () => {
117117
return 'yes';
118118
})
119119
.with(P.object, (obj) => {
120-
type t = Expect<Equal<typeof obj, never>>;
120+
type t = Expect<Equal<typeof obj, {}>>;
121121

122122
return 'no';
123123
})
@@ -132,7 +132,9 @@ describe('Object', () => {
132132
return 'no';
133133
})
134134
.with(P.object, (obj) => {
135-
type t = Expect<Equal<typeof obj, never>>;
135+
type t = Expect<Equal<typeof obj, {
136+
readonly x: 1;
137+
}>>;
136138
return 'yes';
137139
})
138140
.exhaustive();

0 commit comments

Comments
 (0)