Skip to content

Commit

Permalink
Merge pull request #125 from ThomasAribart/fix-bug-with-constraint
Browse files Browse the repository at this point in the history
Fix bug with constraint
  • Loading branch information
ThomasAribart authored Feb 23, 2023
2 parents 5688014 + b239fba commit 5ce318a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/definitions/jsonSchema7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export type JSONSchema7 =
// Required to allow array values in default field
// https://github.com/ThomasAribart/json-schema-to-ts/issues/80
default?: unknown;
[key: string]: unknown;
});

export type JSONSchema7Reference = JSONSchema7 & { $id: string };
7 changes: 0 additions & 7 deletions src/definitions/jsonSchema7.type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,3 @@ const schemaWithArrayDefault: JSONSchema = {
},
} as const;
schemaWithArrayDefault;

// Should work with extended schema (custom property)
const schemaWithCustomProperty: JSONSchema = {
type: "object",
transform: ["trim"],
} as const;
schemaWithCustomProperty;
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ export type JSONSchema = JSONSchema7;
export type FromSchema<
S extends JSONSchema,
Opt extends FromSchemaOptions = FromSchemaDefaultOptions,
W extends $JSONSchema7 = Writable<S>,
W extends $JSONSchema7 = S extends Record<string | number | symbol, unknown>
? Writable<S>
: S,
> = M.$Resolve<ParseSchema<W, ParseOptions<W, Opt>>>;
18 changes: 18 additions & 0 deletions src/tests/readme/not.type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ type AssertOddNumber = A.Equals<ReceivedOddNumber, ExpectedOddNumber>;
const assertOddNumber: AssertOddNumber = 1;
assertOddNumber;

// Incorrect

const incorrectSchema = {
type: "number",
not: { bogus: "option" },
} as const;

type ReceivedIncorrect = FromSchema<
// @ts-expect-error
typeof incorrectSchema,
{ parseNotKeyword: true }
>;
type ExpectedIncorrect = unknown;

type AssertIncorrect = A.Equals<ReceivedIncorrect, ExpectedIncorrect>;
const assertIncorrect: AssertIncorrect = 1;
assertIncorrect;

// Refinment types

const goodLanguageSchema = {
Expand Down

0 comments on commit 5ce318a

Please sign in to comment.