Skip to content

Commit b239fba

Browse files
author
ThomasAribart
committed
Fix bug with constraints
1 parent 5688014 commit b239fba

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/definitions/jsonSchema7.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export type JSONSchema7 =
5454
// Required to allow array values in default field
5555
// https://github.com/ThomasAribart/json-schema-to-ts/issues/80
5656
default?: unknown;
57-
[key: string]: unknown;
5857
});
5958

6059
export type JSONSchema7Reference = JSONSchema7 & { $id: string };

src/definitions/jsonSchema7.type.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,3 @@ const schemaWithArrayDefault: JSONSchema = {
4444
},
4545
} as const;
4646
schemaWithArrayDefault;
47-
48-
// Should work with extended schema (custom property)
49-
const schemaWithCustomProperty: JSONSchema = {
50-
type: "object",
51-
transform: ["trim"],
52-
} as const;
53-
schemaWithCustomProperty;

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ export type JSONSchema = JSONSchema7;
4747
export type FromSchema<
4848
S extends JSONSchema,
4949
Opt extends FromSchemaOptions = FromSchemaDefaultOptions,
50-
W extends $JSONSchema7 = Writable<S>,
50+
W extends $JSONSchema7 = S extends Record<string | number | symbol, unknown>
51+
? Writable<S>
52+
: S,
5153
> = M.$Resolve<ParseSchema<W, ParseOptions<W, Opt>>>;

src/tests/readme/not.type.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ type AssertOddNumber = A.Equals<ReceivedOddNumber, ExpectedOddNumber>;
101101
const assertOddNumber: AssertOddNumber = 1;
102102
assertOddNumber;
103103

104+
// Incorrect
105+
106+
const incorrectSchema = {
107+
type: "number",
108+
not: { bogus: "option" },
109+
} as const;
110+
111+
type ReceivedIncorrect = FromSchema<
112+
// @ts-expect-error
113+
typeof incorrectSchema,
114+
{ parseNotKeyword: true }
115+
>;
116+
type ExpectedIncorrect = unknown;
117+
118+
type AssertIncorrect = A.Equals<ReceivedIncorrect, ExpectedIncorrect>;
119+
const assertIncorrect: AssertIncorrect = 1;
120+
assertIncorrect;
121+
104122
// Refinment types
105123

106124
const goodLanguageSchema = {

0 commit comments

Comments
 (0)