File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' fets ' : patch
3
+ ---
4
+
5
+ Fix nested circular references
Original file line number Diff line number Diff line change @@ -159,6 +159,20 @@ type RangedJSONSchema<T extends { minimum: number; maximum: number }> = T extend
159
159
} ? MIN extends number ? MAX extends number ? IntRange<MIN, MAX> : never : never : never;
160
160
*/
161
161
162
+ export type Circular < TJSONSchema extends JSONSchema > = TJSONSchema extends {
163
+ properties : { [ key : string ] : JSONSchema } ;
164
+ }
165
+ ? TJSONSchema extends PropertyValue < TJSONSchema , Property < TJSONSchema > >
166
+ ? true
167
+ : Circular < PropertyValue < TJSONSchema , Property < TJSONSchema > > >
168
+ : false ;
169
+
170
+ export type Property < TJSONSchema extends JSONSchema > = keyof TJSONSchema [ 'properties' ] ;
171
+ export type PropertyValue <
172
+ TJSONSchema extends JSONSchema ,
173
+ TProperty extends keyof TJSONSchema [ 'properties' ] ,
174
+ > = TJSONSchema [ 'properties' ] [ TProperty ] ;
175
+
162
176
export type FromSchema < T > =
163
177
/* T extends { type: 'integer'; minimum: number; maximum: number } ? RangedJSONSchema<T> : */ T extends {
164
178
static : infer U ;
@@ -168,9 +182,8 @@ export type FromSchema<T> =
168
182
? FromSchemaOriginal <
169
183
T ,
170
184
{
171
- deserialize : T extends T [ 'properties' ] [ keyof T [ 'properties' ] ]
172
- ? false
173
- : [
185
+ deserialize : Circular < T > extends false
186
+ ? [
174
187
{
175
188
pattern : {
176
189
type : 'string' ;
@@ -192,7 +205,8 @@ export type FromSchema<T> =
192
205
} ;
193
206
output : bigint | number ;
194
207
} ,
195
- ] ;
208
+ ]
209
+ : false ;
196
210
}
197
211
>
198
212
: never ;
Original file line number Diff line number Diff line change 1
1
import {
2
2
createClient ,
3
3
OASJSONResponseSchema ,
4
+ OASModel ,
4
5
OASOutput ,
5
6
type FromSchema ,
6
7
type NormalizeOAS ,
@@ -72,3 +73,14 @@ if (response.ok) {
72
73
} else {
73
74
console . log ( response . status ) ;
74
75
}
76
+
77
+ type NodeA = OASModel < NormalizedOAS , 'Node' > ;
78
+ const nodeA = { } as NodeA ;
79
+ const numberA = nodeA . child ?. child ?. child ?. child ?. number ;
80
+ type NumberA = typeof numberA ;
81
+ let numberAVar : NumberA ;
82
+ numberAVar = 2 ;
83
+ // @ts -expect-error - numberAVar is a number
84
+ numberAVar = 'a' ;
85
+
86
+ console . log ( numberAVar ) ;
You can’t perform that action at this time.
0 commit comments