Skip to content

type & $$type seem to be ambiguous in the documentation #348

Description

@fugufish

The documentaiton is ambiguous about the difference between `type and $$type. For example this test on enum:

	it("allows enums in a nested schema", () => {
		const check = v.compile({type: "object", value: {$$type: "enum", values: ["a", "b", "c"]}});

		expect(check({value: "a"})).toBe(true);
		expect(check({value: "z"})).toBe(false);
	})

fails with the following result:

Cannot read properties of undefined (reading 'join')

However this

	it("allows enums in a nested schema", () => {
		const check = v.compile({type: "object", value: {type: "enum", values: ["a", "b", "c"]}});

		expect(check({value: "a"})).toBe(true);
		expect(check({value: "z"})).toBe(false);
	})

falis with

Expected: true
Received: [{"actual": undefined, "field": "type", "message": "The 'type' field is required.", "type": "required"}]

this means that $$type and type are not interchangable. $$type triggers the enum rule to be run, but the schema of the rule is changed causing it to throw an exception (i have a fix for that if needed), but type will not cause the rule to be run at all.

What is the expected behavior?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions