Skip to content

Commit 3771320

Browse files
Merge fff1399 into 4c110da
2 parents 4c110da + fff1399 commit 3771320

File tree

8 files changed

+37
-20
lines changed

8 files changed

+37
-20
lines changed

.changeset/itchy-pumas-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@toomuchdesign/json-schema-fns': minor
3+
---
4+
5+
Remove unnecessary `Readonly` invocations

.changeset/three-masks-read.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@toomuchdesign/json-schema-fns': minor
3+
---
4+
5+
Remove unnecessary `Simplify` invocations

src/mergeProps.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
MergeOptionalRecords,
66
MergeOptionalTuples,
77
MergeRecords,
8+
Simplify,
89
} from './utils/types';
910

1011
type MergeProps<
@@ -13,11 +14,19 @@ type MergeProps<
1314
> = MergeRecords<
1415
MergeRecords<Schema1, Schema2>,
1516
{
16-
required: MergeOptionalTuples<Schema1['required'], Schema2['required']>;
17-
properties: MergeRecords<Schema1['properties'], Schema2['properties']>;
18-
patternProperties: MergeOptionalRecords<
19-
Schema1['patternProperties'],
20-
Schema2['patternProperties']
17+
readonly required: Readonly<
18+
MergeOptionalTuples<Schema1['required'], Schema2['required']>
19+
>;
20+
readonly properties: Simplify<
21+
Readonly<MergeRecords<Schema1['properties'], Schema2['properties']>>
22+
>;
23+
readonly patternProperties: Simplify<
24+
Readonly<
25+
MergeOptionalRecords<
26+
Schema1['patternProperties'],
27+
Schema2['patternProperties']
28+
>
29+
>
2130
>;
2231
}
2332
>;

src/sealSchemaDeep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type DisableAdditionalPropertiesDeep<Value> = Value extends object
1717
>
1818
>
1919
: // Any other object/array
20-
Readonly<{
20+
{
2121
[Key in keyof Value]: DisableAdditionalPropertiesDeep<Value[Key]>;
22-
}>
22+
}
2323
: // Any other primitive
2424
Value;
2525

src/unsealSchemaDeep.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import type { JSONSchema, JSONSchemaObjectOutput } from './utils/types';
44
type OmitAdditionalPropertiesDeep<Value> = Value extends object
55
? Value extends { type: 'object' }
66
? // JSON schema object type
7-
Readonly<{
7+
{
88
[Key in keyof Omit<
99
Value,
1010
'additionalProperties'
1111
>]: OmitAdditionalPropertiesDeep<Value[Key]>;
12-
}>
12+
}
1313
: // Any other object/array
14-
Readonly<{
14+
{
1515
[Key in keyof Value]: OmitAdditionalPropertiesDeep<Value[Key]>;
16-
}>
16+
}
1717
: // Any other primitive
1818
Value;
1919

src/utils/types/definitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MergeRecords, OmitByValue, Simplify } from './records';
1+
import type { MergeRecords, OmitByValue } from './records';
22

33
// https://github.com/ThomasAribart/json-schema-to-ts/blob/12767c1eab895159c01f5e6898d8e5e711ff9d1c/src/definitions/jsonSchema.ts
44
export type JSONSchema = Readonly<{
@@ -17,6 +17,6 @@ export type JSONSchemaObject = MergeRecords<
1717
}
1818
>;
1919

20-
export type JSONSchemaObjectOutput<Schema extends JSONSchema> =
20+
export type JSONSchemaObjectOutput<Schema extends Record<string, unknown>> =
2121
// Remove undefined props and empty arrays
2222
OmitByValue<Schema, readonly [] | undefined>;

src/utils/types/records.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
1111
export type MergeRecords<
1212
Destination extends UnknownRecord,
1313
Source extends UnknownRecord,
14-
> = Simplify<Omit<Destination, keyof Source> & Source>;
14+
> = Omit<Destination, keyof Source> & Source;
1515

1616
/**
1717
* Merge two optional records, keeping `undefined` if both are undefined

src/utils/types/tuples.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ export type PickFromTuple<
3232
export type MergeTuples<
3333
T1 extends StringTuple,
3434
T2 extends StringTuple,
35-
> = Readonly<
36-
UnionToTuple<
37-
// Transform tuples to union to remove duplicates
38-
T1[number] | T2[number]
39-
>
35+
> = UnionToTuple<
36+
// Transform tuples to union to remove duplicates
37+
T1[number] | T2[number]
4038
>;
4139

4240
/**
@@ -51,4 +49,4 @@ export type MergeOptionalTuples<
5149
: T1
5250
: T2 extends StringTuple
5351
? T2
54-
: [];
52+
: readonly [];

0 commit comments

Comments
 (0)