Skip to content

Commit fe5615e

Browse files
committed
types(validation): toObject ignores properties stating with $
1 parent 87ad505 commit fe5615e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/vue-composable/__tests__/validation/validation.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ describe("validation", () => {
304304
part2: "part2",
305305
});
306306
});
307+
308+
it("should not keep keys starting with '$'", () => {
309+
const v = useValidation({
310+
$test: "ddd",
311+
age: {
312+
$value: 20,
313+
},
314+
}).toObject();
315+
316+
//@ts-expect-error not to be defined
317+
expect(v.$test).toBe(undefined);
318+
expect(v).toStrictEqual({
319+
age: 20,
320+
});
321+
});
307322
});
308323

309324
describe("render", () => {

packages/vue-composable/src/validation/validation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ type ValidationOutputObject<T extends Record<string, any>> = T extends {
101101
$value: any;
102102
}
103103
? UnwrapRef<T["$value"]>
104-
: { [K in keyof T]: ValidationOutputObject<T[K]> };
104+
: {
105+
[K in keyof T & string as K extends `$${string}`
106+
? never
107+
: K]: ValidationOutputObject<T[K]>;
108+
};
105109

106110
/* /Output */
107111

0 commit comments

Comments
 (0)