diff --git a/src/definitions/jsonSchema7.ts b/src/definitions/jsonSchema7.ts index 86af794..b750876 100644 --- a/src/definitions/jsonSchema7.ts +++ b/src/definitions/jsonSchema7.ts @@ -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 }; diff --git a/src/definitions/jsonSchema7.type.test.ts b/src/definitions/jsonSchema7.type.test.ts index 4728c51..a8c4cf7 100644 --- a/src/definitions/jsonSchema7.type.test.ts +++ b/src/definitions/jsonSchema7.type.test.ts @@ -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; diff --git a/src/index.ts b/src/index.ts index b2cf0b2..c1e758b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,5 +47,7 @@ export type JSONSchema = JSONSchema7; export type FromSchema< S extends JSONSchema, Opt extends FromSchemaOptions = FromSchemaDefaultOptions, - W extends $JSONSchema7 = Writable, + W extends $JSONSchema7 = S extends Record + ? Writable + : S, > = M.$Resolve>>; diff --git a/src/tests/readme/not.type.test.ts b/src/tests/readme/not.type.test.ts index b4d09ca..13a7fbe 100644 --- a/src/tests/readme/not.type.test.ts +++ b/src/tests/readme/not.type.test.ts @@ -101,6 +101,24 @@ type AssertOddNumber = A.Equals; 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; +const assertIncorrect: AssertIncorrect = 1; +assertIncorrect; + // Refinment types const goodLanguageSchema = {