Skip to content

Commit

Permalink
Add support for exactOptionalPropertyTypes #385
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Aug 23, 2024
1 parent 63a8965 commit 4d8a1db
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 148 deletions.
4 changes: 4 additions & 0 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the library will be documented in this file.

## vX.X.X (Month DD, YYYY)

- Add support for `exactOptionalPropertyTypes` config (issue #385)

## v0.38.0 (August 20, 2024)

- Change `expects` and `expected` property by enclosing combined values in parentheses
Expand Down
2 changes: 0 additions & 2 deletions library/src/actions/partialCheck/partialCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ describe('partialCheck', () => {
tuple: [123, { key: 'foo' }, 456],
other: 'bar',
},
issues: undefined,
};
expect(action._run(dataset, {})).toStrictEqual(dataset);
});
Expand All @@ -227,7 +226,6 @@ describe('partialCheck', () => {
const dataset: TypedDataset<Input, never> = {
typed: true,
value: input,
issues: undefined,
};
expect(action._run(dataset, {})).toStrictEqual({
...dataset,
Expand Down
2 changes: 0 additions & 2 deletions library/src/actions/partialCheck/partialCheckAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ describe('partialCheckAsync', () => {
tuple: [123, { key: 'foo' }, 456],
other: 'bar',
},
issues: undefined,
};
expect(await action._run(dataset, {})).toStrictEqual(dataset);
});
Expand All @@ -231,7 +230,6 @@ describe('partialCheckAsync', () => {
const dataset: TypedDataset<Input, never> = {
typed: true,
value: input,
issues: undefined,
};
expect(await action._run(dataset, {})).toStrictEqual({
...dataset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ describe('_isPartiallyTyped', () => {
const dataset: TypedDataset<Input, never> = {
typed: true,
value: input,
issues: undefined,
};
expect(_isPartiallyTyped(dataset, pathList)).toBe(true);
});
Expand Down
12 changes: 6 additions & 6 deletions library/src/actions/rawCheck/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export interface RawCheckIssue<TInput> extends BaseIssue<TInput> {
* Issue info type.
*/
interface IssueInfo<TInput> {
label?: string;
input?: unknown;
expected?: string;
received?: string;
message?: ErrorMessage<RawCheckIssue<TInput>>;
path?: [IssuePathItem, ...IssuePathItem[]];
label?: string | undefined;
input?: unknown | undefined;
expected?: string | undefined;
received?: string | undefined;
message?: ErrorMessage<RawCheckIssue<TInput>> | undefined;
path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions library/src/actions/rawTransform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export interface RawTransformIssue<TInput> extends BaseIssue<TInput> {
* Issue info type.
*/
interface IssueInfo<TInput> {
label?: string;
input?: unknown;
expected?: string;
received?: string;
message?: ErrorMessage<RawTransformIssue<TInput>>;
path?: [IssuePathItem, ...IssuePathItem[]];
label?: string | undefined;
input?: unknown | undefined;
expected?: string | undefined;
received?: string | undefined;
message?: ErrorMessage<RawTransformIssue<TInput>> | undefined;
path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
}

/**
Expand Down
52 changes: 26 additions & 26 deletions library/src/methods/partial/partial.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ describe('partial', () => {
describe('should infer correct types', () => {
test('of input', () => {
expectTypeOf<InferInput<Schema1>>().toEqualTypeOf<{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number | null;
}>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<{
key1?: string | undefined;
key1?: string;
key2: number;
key3?: string | undefined;
key4?: number | null | undefined;
key3?: string;
key4?: number | null;
}>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema1>>().toEqualTypeOf<{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number;
}>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<{
key1?: string | undefined;
key1?: string;
key2: number;
key3?: string | undefined;
key3?: string;
key4: number;
}>();
});
Expand Down Expand Up @@ -105,36 +105,36 @@ describe('partial', () => {
test('of input', () => {
expectTypeOf<InferInput<Schema1>>().toEqualTypeOf<
{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number | null;
} & { [key: string]: boolean }
>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<
{
key1: string;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key2?: number;
key3?: string;
key4?: number | null;
} & { [key: string]: boolean }
>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema1>>().toEqualTypeOf<
{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number;
} & { [key: string]: boolean }
>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<
{
key1: string;
key2?: number | undefined;
key3?: string | undefined;
key2?: number;
key3?: string;
key4: number;
} & { [key: string]: boolean }
>();
Expand Down
52 changes: 26 additions & 26 deletions library/src/methods/partial/partialAsync.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ describe('partialAsync', () => {
describe('should infer correct types', () => {
test('of input', () => {
expectTypeOf<InferInput<Schema1>>().toEqualTypeOf<{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number | null;
}>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<{
key1?: string | undefined;
key1?: string;
key2: number;
key3?: string | undefined;
key4?: number | null | undefined;
key3?: string;
key4?: number | null;
}>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema1>>().toEqualTypeOf<{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number;
}>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<{
key1?: string | undefined;
key1?: string;
key2: number;
key3?: string | undefined;
key3?: string;
key4: number;
}>();
});
Expand Down Expand Up @@ -105,36 +105,36 @@ describe('partialAsync', () => {
test('of input', () => {
expectTypeOf<InferInput<Schema1>>().toEqualTypeOf<
{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number | null;
} & { [key: string]: boolean }
>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<
{
key1: string;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | null | undefined;
key2?: number;
key3?: string;
key4?: number | null;
} & { [key: string]: boolean }
>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema1>>().toEqualTypeOf<
{
key1?: string | undefined;
key2?: number | undefined;
key3?: string | undefined;
key4?: number | undefined;
key1?: string;
key2?: number;
key3?: string;
key4?: number;
} & { [key: string]: boolean }
>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<
{
key1: string;
key2?: number | undefined;
key3?: string | undefined;
key2?: number;
key3?: string;
key4: number;
} & { [key: string]: boolean }
>();
Expand Down
12 changes: 6 additions & 6 deletions library/src/methods/required/required.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe('required', () => {
}>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<{
key1: string;
key2?: number | undefined;
key2?: number;
key3: string;
key4?: number | null | undefined;
key4?: number | null;
}>();
});

Expand All @@ -70,7 +70,7 @@ describe('required', () => {
}>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<{
key1: string;
key2?: number | undefined;
key2?: number;
key3: string;
key4: number;
}>();
Expand Down Expand Up @@ -119,10 +119,10 @@ describe('required', () => {
>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<
{
key1?: string | undefined;
key1?: string;
key2: number;
key3: string;
key4?: number | null | undefined;
key4?: number | null;
} & { [key: string]: boolean }
>();
});
Expand All @@ -138,7 +138,7 @@ describe('required', () => {
>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<
{
key1?: string | undefined;
key1?: string;
key2: number;
key3: string;
key4: number;
Expand Down
12 changes: 6 additions & 6 deletions library/src/methods/required/requiredAsync.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ describe('requiredAsync', () => {
}>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<{
key1: string;
key2?: number | undefined;
key2?: number;
key3: string;
key4?: number | null | undefined;
key4?: number | null;
}>();
});

Expand All @@ -78,7 +78,7 @@ describe('requiredAsync', () => {
}>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<{
key1: string;
key2?: number | undefined;
key2?: number;
key3: string;
key4: number;
}>();
Expand Down Expand Up @@ -131,10 +131,10 @@ describe('requiredAsync', () => {
>();
expectTypeOf<InferInput<Schema2>>().toEqualTypeOf<
{
key1?: string | undefined;
key1?: string;
key2: number;
key3: string;
key4?: number | null | undefined;
key4?: number | null;
} & { [key: string]: boolean }
>();
});
Expand All @@ -150,7 +150,7 @@ describe('requiredAsync', () => {
>();
expectTypeOf<InferOutput<Schema2>>().toEqualTypeOf<
{
key1?: string | undefined;
key1?: string;
key2: number;
key3: string;
key4: number;
Expand Down
6 changes: 3 additions & 3 deletions library/src/schemas/looseObject/looseObject.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('looseObject', () => {
expectTypeOf<InferInput<Schema>>().toEqualTypeOf<
{
key1: string;
key2?: string | undefined;
key3?: string | null | undefined;
key2?: string;
key3?: string | null;
key4: { key: number };
key5: string;
} & { [key: string]: unknown }
Expand All @@ -67,7 +67,7 @@ describe('looseObject', () => {
{
key1: string;
key2: string;
key3?: string | null | undefined;
key3?: string | null;
key4: { key: number };
readonly key5: string;
} & { [key: string]: unknown }
Expand Down
2 changes: 2 additions & 0 deletions library/src/schemas/looseObject/looseObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('looseObject', () => {
test('for optional entry', () => {
expectNoSchemaIssue(looseObject({ key: optional(string()) }), [
{},
// @ts-expect-error
{ key: undefined },
{ key: 'foo' },
]);
Expand All @@ -142,6 +143,7 @@ describe('looseObject', () => {
test('for nullish entry', () => {
expectNoSchemaIssue(looseObject({ key: nullish(number()) }), [
{},
// @ts-expect-error
{ key: undefined },
{ key: null },
{ key: 123 },
Expand Down
Loading

0 comments on commit 4d8a1db

Please sign in to comment.