Skip to content

Commit 7597115

Browse files
committed
chore: slightly better reach types
1 parent 2b4773c commit 7597115

File tree

5 files changed

+826
-919
lines changed

5 files changed

+826
-919
lines changed

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
]
6565
},
6666
"devDependencies": {
67-
"@4c/cli": "^3.0.1",
68-
"@4c/rollout": "^3.0.1",
67+
"@4c/cli": "^4.0.1",
68+
"@4c/rollout": "^4.0.1",
6969
"@4c/tsconfig": "^0.4.1",
7070
"@babel/cli": "^7.18.10",
7171
"@babel/core": "^7.18.10",
@@ -90,9 +90,9 @@
9090
"eslint-plugin-typescript": "^0.14.0",
9191
"hookem": "^2.0.1",
9292
"jest": "^27.5.1",
93-
"lint-staged": "^12.5.0",
93+
"lint-staged": "^13.0.3",
9494
"prettier": "^2.7.1",
95-
"rollup": "^2.78.0",
95+
"rollup": "^2.78.1",
9696
"rollup-plugin-babel": "^4.4.0",
9797
"rollup-plugin-dts": "^4.2.2",
9898
"rollup-plugin-filesize": "^9.1.2",
@@ -101,8 +101,8 @@
101101
"typescript": "^4.7.4"
102102
},
103103
"dependencies": {
104-
"property-expr": "^2.0.4",
105-
"tiny-case": "^1.0.2",
104+
"property-expr": "^2.0.5",
105+
"tiny-case": "^1.0.3",
106106
"toposort": "^2.0.2"
107107
}
108108
}

src/object.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type { AnyObject };
2929
type MakeKeysOptional<T> = T extends AnyObject ? _<MakePartial<T>> : T;
3030

3131
export type Shape<T extends Maybe<AnyObject>, C = AnyObject> = {
32-
[field in keyof T]: ISchema<T[field], C> | Reference;
32+
[field in keyof T]-?: ISchema<T[field], C> | Reference;
3333
};
3434

3535
export type ObjectSchemaSpec = SchemaSpec<any> & {
@@ -212,7 +212,10 @@ export default class ObjectSchema<
212212
intermediateValue[prop] = value[prop];
213213
}
214214

215-
if (intermediateValue[prop] !== value[prop]) {
215+
if (
216+
exists !== prop in intermediateValue ||
217+
intermediateValue[prop] !== value[prop]
218+
) {
216219
isChanged = true;
217220
}
218221
}

src/util/reach.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { forEach } from 'property-expr';
2+
import type Reference from '../Reference';
3+
import type { ISchema } from '../types';
24

35
let trim = (part: string) => part.substr(0, part.length - 1).substr(1);
46

@@ -7,7 +9,11 @@ export function getIn<C = any>(
79
path: string,
810
value?: any,
911
context: C = value,
10-
) {
12+
): {
13+
schema: ISchema<any> | Reference;
14+
parent: any;
15+
parentPath: string;
16+
} {
1117
let parent: any, lastPart: string, lastPartDebug: string;
1218

1319
// root path: ''

test/types/types.ts

+11
Original file line numberDiff line numberDiff line change
@@ -962,3 +962,14 @@ Conditions: {
962962
.when('foo', ([foo]) => (foo ? string() : number()))
963963
.min(1);
964964
}
965+
966+
TypeAssigning: {
967+
// $ExpectError unknown is not assignable to () => any
968+
const _schema: ObjectSchema<{
969+
mtime?: Date | null | undefined;
970+
toJSON: () => any;
971+
}> = object({
972+
mtime: date().nullable(),
973+
toJSON: mixed().required(),
974+
});
975+
}

0 commit comments

Comments
 (0)