Skip to content

Commit

Permalink
Merge pull request #136 from ThomasAribart/fix-bug-with-extended-schemas
Browse files Browse the repository at this point in the history
Fix bug with extended schemas
  • Loading branch information
ThomasAribart committed May 10, 2023
2 parents 95fe596 + f383f9c commit e20ee01
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ jobs:
strategy:
matrix:
node: [16, 18]
typescript: [
"~4.5.5",
"~4.7.4",
"~4.8.3",
"~4.9.5",
# TODO: Fix FromSchema in those versions
# "~5.0.4",
# "latest",
]
typescript: ["~4.5.5", "~4.7.4", "~4.8.3", "~4.9.5", "~5.0.4", "latest"]
name: Node ${{ matrix.node }} / TS ${{ matrix.typescript }}
steps:
- name: "Checkout latest code"
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/extendedJsonSchema7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type UnextendJSONSchema7Record<

export type UnextendJSONSchema7<
E extends JSONSchema7Extension,
S extends ExtendedJSONSchema7<E>,
S,
> = S extends boolean
? S
: {
Expand Down
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
} from "./definitions";
import type { ParseOptions } from "./parse-options";
import type { ParseSchema } from "./parse-schema";
import type { Cast, Readonly, Writable } from "./type-utils";
import type { Readonly, Writable } from "./type-utils";

export type {
DeserializationPattern,
Expand Down Expand Up @@ -88,8 +88,5 @@ export type FromExtendedSchema<
E extends JSONSchema7Extension,
S extends ExtendedJSONSchema<E>,
Opt extends FromExtendedSchemaOptions<E> = FromSchemaDefaultOptions,
W extends $ExtendedJSONSchema7<E> = Cast<
S extends Record<string | number | symbol, unknown> ? Writable<S> : S,
$ExtendedJSONSchema7<E>
>,
> = FromSchema<Cast<UnextendJSONSchema7<E, W>, JSONSchema>, Opt>;
U = UnextendJSONSchema7<E, S>,
> = U extends JSONSchema ? FromSchema<U, Opt> : never;
30 changes: 29 additions & 1 deletion src/tests/readme/extensions.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type BigInt = FromExtendedSchema<
CustomProps,
typeof bigIntSchema,
{
// 👇 Works very well with the deserialize option!
deserialize: [
{
pattern: {
Expand All @@ -49,3 +48,32 @@ type BigInt = FromExtendedSchema<
type AssertBigInt = A.Equals<BigInt, bigint>;
const assertBigInt: AssertBigInt = 1;
assertBigInt;

const nestedSchema = {
type: "object",
properties: {
nested: {
numberType: "bigInt",
},
},
required: ["nested"],
additionalProperties: false,
} as const;

type NestedBigInt = FromExtendedSchema<
CustomProps,
typeof nestedSchema,
{
deserialize: [
{
pattern: {
numberType: "bigInt";
};
output: bigint;
},
];
}
>;
type AssertNestedBigInt = A.Equals<NestedBigInt, { nested: bigint }>;
const assertNestedBigInt: AssertNestedBigInt = 1;
assertNestedBigInt;
8 changes: 0 additions & 8 deletions src/type-utils/cast.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/type-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export type { And } from "./and";
export type { Cast } from "./cast";
export type { Compute } from "./compute";
export type { DoesExtend } from "./extends";
export type { DeepGet } from "./get";
Expand Down

0 comments on commit e20ee01

Please sign in to comment.