Skip to content

Commit 62529d2

Browse files
committed
Investigate, understand and partially resolve TS errors
1 parent 6596020 commit 62529d2

File tree

2 files changed

+52
-132
lines changed

2 files changed

+52
-132
lines changed

packages/to-json-schema/src/convertAction.test.ts

Lines changed: 41 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ describe('convertAction', () => {
8888
expect(
8989
convertAction(
9090
{ type: 'string' },
91-
// @ts-expect-error FIXME: Something is wrong here
92-
v.length<string, 3>(3),
91+
v.length<v.LengthInput, 3>(3),
9392
undefined
9493
)
9594
).toStrictEqual({
@@ -101,12 +100,7 @@ describe('convertAction', () => {
101100

102101
test('should convert length action for arrays', () => {
103102
expect(
104-
convertAction(
105-
{ type: 'array' },
106-
// @ts-expect-error FIXME: Something is wrong here
107-
v.length<unknown[], 3>(3),
108-
undefined
109-
)
103+
convertAction({ type: 'array' }, v.length<v.LengthInput, 3>(3), undefined)
110104
).toStrictEqual({
111105
type: 'array',
112106
minItems: 3,
@@ -116,31 +110,20 @@ describe('convertAction', () => {
116110

117111
test('should throw error for length action with invalid type', () => {
118112
expect(() =>
119-
convertAction(
120-
{},
121-
// @ts-expect-error FIXME: Something is wrong here
122-
v.length<unknown, 3>(3),
123-
undefined
124-
)
113+
convertAction({}, v.length<v.LengthInput, 3>(3), undefined)
125114
).toThrowError('The "length" action is not supported on type "undefined".');
126115
expect(() =>
127116
convertAction(
128117
{ type: 'object' },
129-
// @ts-expect-error FIXME: Something is wrong here
130-
v.length<unknown, 3>(3),
118+
v.length<v.LengthInput, 3>(3),
131119
undefined
132120
)
133121
).toThrowError('The "length" action is not supported on type "object".');
134122
});
135123

136124
test('should force conversion for length action with invalid type', () => {
137125
expect(
138-
convertAction(
139-
{},
140-
// @ts-expect-error FIXME: Something is wrong here
141-
v.length<unknown, 3>(3),
142-
{ force: true }
143-
)
126+
convertAction({}, v.length<v.LengthInput, 3>(3), { force: true })
144127
).toStrictEqual({
145128
minLength: 3,
146129
maxLength: 3,
@@ -149,12 +132,9 @@ describe('convertAction', () => {
149132
'The "length" action is not supported on type "undefined".'
150133
);
151134
expect(
152-
convertAction(
153-
{ type: 'object' },
154-
// @ts-expect-error FIXME: Something is wrong here
155-
v.length<unknown, 3>(3),
156-
{ force: true }
157-
)
135+
convertAction({ type: 'object' }, v.length<v.LengthInput, 3>(3), {
136+
force: true,
137+
})
158138
).toStrictEqual({ type: 'object', minLength: 3, maxLength: 3 });
159139
expect(console.warn).toHaveBeenLastCalledWith(
160140
'The "length" action is not supported on type "object".'
@@ -165,8 +145,7 @@ describe('convertAction', () => {
165145
expect(
166146
convertAction(
167147
{ type: 'string' },
168-
// @ts-expect-error FIXME: Something is wrong here
169-
v.minLength<string, 3>(3),
148+
v.minLength<v.LengthInput, 3>(3),
170149
undefined
171150
)
172151
).toStrictEqual({
@@ -179,8 +158,7 @@ describe('convertAction', () => {
179158
expect(
180159
convertAction(
181160
{ type: 'array' },
182-
// @ts-expect-error FIXME: Something is wrong here
183-
v.minLength<unknown[], 3>(3),
161+
v.minLength<v.LengthInput, 3>(3),
184162
undefined
185163
)
186164
).toStrictEqual({
@@ -191,20 +169,14 @@ describe('convertAction', () => {
191169

192170
test('should throw error for min length action with invalid type', () => {
193171
expect(() =>
194-
convertAction(
195-
{},
196-
// @ts-expect-error FIXME: Something is wrong here
197-
v.minLength<unknown, 3>(3),
198-
undefined
199-
)
172+
convertAction({}, v.minLength<v.LengthInput, 3>(3), undefined)
200173
).toThrowError(
201174
'The "min_length" action is not supported on type "undefined".'
202175
);
203176
expect(() =>
204177
convertAction(
205178
{ type: 'object' },
206-
// @ts-expect-error FIXME: Something is wrong here
207-
v.minLength<unknown, 3>(3),
179+
v.minLength<v.LengthInput, 3>(3),
208180
undefined
209181
)
210182
).toThrowError(
@@ -214,25 +186,17 @@ describe('convertAction', () => {
214186

215187
test('should force conversion for min length action with invalid type', () => {
216188
expect(
217-
convertAction(
218-
{},
219-
// @ts-expect-error FIXME: Something is wrong here
220-
v.minLength<unknown, 3>(3),
221-
{ force: true }
222-
)
189+
convertAction({}, v.minLength<v.LengthInput, 3>(3), { force: true })
223190
).toStrictEqual({
224191
minLength: 3,
225192
});
226193
expect(console.warn).toHaveBeenLastCalledWith(
227194
'The "min_length" action is not supported on type "undefined".'
228195
);
229196
expect(
230-
convertAction(
231-
{ type: 'object' },
232-
// @ts-expect-error FIXME: Something is wrong here
233-
v.minLength<unknown, 3>(3),
234-
{ force: true }
235-
)
197+
convertAction({ type: 'object' }, v.minLength<v.LengthInput, 3>(3), {
198+
force: true,
199+
})
236200
).toStrictEqual({ type: 'object', minLength: 3 });
237201
expect(console.warn).toHaveBeenLastCalledWith(
238202
'The "min_length" action is not supported on type "object".'
@@ -243,8 +207,7 @@ describe('convertAction', () => {
243207
expect(
244208
convertAction(
245209
{ type: 'string' },
246-
// @ts-expect-error FIXME: Something is wrong here
247-
v.maxLength<string, 3>(3),
210+
v.maxLength<v.LengthInput, 3>(3),
248211
undefined
249212
)
250213
).toStrictEqual({
@@ -257,8 +220,7 @@ describe('convertAction', () => {
257220
expect(
258221
convertAction(
259222
{ type: 'array' },
260-
// @ts-expect-error FIXME: Something is wrong here
261-
v.maxLength<unknown[], 3>(3),
223+
v.maxLength<v.LengthInput, 3>(3),
262224
undefined
263225
)
264226
).toStrictEqual({
@@ -269,20 +231,14 @@ describe('convertAction', () => {
269231

270232
test('should throw error for max length action with invalid type', () => {
271233
expect(() =>
272-
convertAction(
273-
{},
274-
// @ts-expect-error FIXME: Something is wrong here
275-
v.maxLength<unknown, 3>(3),
276-
undefined
277-
)
234+
convertAction({}, v.maxLength<v.LengthInput, 3>(3), undefined)
278235
).toThrowError(
279236
'The "max_length" action is not supported on type "undefined".'
280237
);
281238
expect(() =>
282239
convertAction(
283240
{ type: 'object' },
284-
// @ts-expect-error FIXME: Something is wrong here
285-
v.maxLength<unknown, 3>(3),
241+
v.maxLength<v.LengthInput, 3>(3),
286242
undefined
287243
)
288244
).toThrowError(
@@ -292,25 +248,17 @@ describe('convertAction', () => {
292248

293249
test('should force conversion for max length action with invalid type', () => {
294250
expect(
295-
convertAction(
296-
{},
297-
// @ts-expect-error FIXME: Something is wrong here
298-
v.maxLength<unknown, 3>(3),
299-
{ force: true }
300-
)
251+
convertAction({}, v.maxLength<v.LengthInput, 3>(3), { force: true })
301252
).toStrictEqual({
302253
maxLength: 3,
303254
});
304255
expect(console.warn).toHaveBeenLastCalledWith(
305256
'The "max_length" action is not supported on type "undefined".'
306257
);
307258
expect(
308-
convertAction(
309-
{ type: 'object' },
310-
// @ts-expect-error FIXME: Something is wrong here
311-
v.maxLength<unknown, 3>(3),
312-
{ force: true }
313-
)
259+
convertAction({ type: 'object' }, v.maxLength<v.LengthInput, 3>(3), {
260+
force: true,
261+
})
314262
).toStrictEqual({ type: 'object', maxLength: 3 });
315263
expect(console.warn).toHaveBeenLastCalledWith(
316264
'The "max_length" action is not supported on type "object".'
@@ -321,8 +269,7 @@ describe('convertAction', () => {
321269
expect(
322270
convertAction(
323271
{ type: 'number' },
324-
// @ts-expect-error FIXME: Something is wrong here
325-
v.maxValue<number, 3>(3),
272+
v.maxValue<v.ValueInput, 3>(3),
326273
undefined
327274
)
328275
).toStrictEqual({
@@ -333,46 +280,32 @@ describe('convertAction', () => {
333280

334281
test('should throw error for max value action with invalid type', () => {
335282
expect(() =>
336-
convertAction(
337-
{},
338-
// @ts-expect-error FIXME: Something is wrong here
339-
v.maxValue<unknown, 3>(3),
340-
undefined
341-
)
283+
convertAction({}, v.maxValue<v.ValueInput, 3>(3), undefined)
342284
).toThrowError(
343285
'The "max_value" action is not supported on type "undefined".'
344286
);
345287
expect(() =>
346288
convertAction(
347289
{ type: 'string' },
348-
// @ts-expect-error FIXME: Something is wrong here
349-
v.maxValue<string, 3>(3),
290+
v.maxValue<v.ValueInput, 3>(3),
350291
undefined
351292
)
352293
).toThrowError('The "max_value" action is not supported on type "string".');
353294
});
354295

355296
test('should force conversion for max value action with invalid type', () => {
356297
expect(
357-
convertAction(
358-
{},
359-
// @ts-expect-error FIXME: Something is wrong here
360-
v.maxValue<unknown, 3>(3),
361-
{ force: true }
362-
)
298+
convertAction({}, v.maxValue<v.ValueInput, 3>(3), { force: true })
363299
).toStrictEqual({
364300
maximum: 3,
365301
});
366302
expect(console.warn).toHaveBeenLastCalledWith(
367303
'The "max_value" action is not supported on type "undefined".'
368304
);
369305
expect(
370-
convertAction(
371-
{ type: 'string' },
372-
// @ts-expect-error FIXME: Something is wrong here
373-
v.maxValue<string, 3>(3),
374-
{ force: true }
375-
)
306+
convertAction({ type: 'string' }, v.maxValue<v.ValueInput, 3>(3), {
307+
force: true,
308+
})
376309
).toStrictEqual({ type: 'string', maximum: 3 });
377310
expect(console.warn).toHaveBeenLastCalledWith(
378311
'The "max_value" action is not supported on type "string".'
@@ -383,8 +316,7 @@ describe('convertAction', () => {
383316
expect(
384317
convertAction(
385318
{ type: 'number' },
386-
// @ts-expect-error FIXME: Something is wrong here
387-
v.minValue<number, 3>(3),
319+
v.minValue<v.ValueInput, 3>(3),
388320
undefined
389321
)
390322
).toStrictEqual({
@@ -395,46 +327,32 @@ describe('convertAction', () => {
395327

396328
test('should throw error for min value action with invalid type', () => {
397329
expect(() =>
398-
convertAction(
399-
{},
400-
// @ts-expect-error FIXME: Something is wrong here
401-
v.minValue<unknown, 3>(3),
402-
undefined
403-
)
330+
convertAction({}, v.minValue<v.ValueInput, 3>(3), undefined)
404331
).toThrowError(
405332
'The "min_value" action is not supported on type "undefined".'
406333
);
407334
expect(() =>
408335
convertAction(
409336
{ type: 'string' },
410-
// @ts-expect-error FIXME: Something is wrong here
411-
v.minValue<string, 3>(3),
337+
v.minValue<v.ValueInput, 3>(3),
412338
undefined
413339
)
414340
).toThrowError('The "min_value" action is not supported on type "string".');
415341
});
416342

417343
test('should force conversion for min value action with invalid type', () => {
418344
expect(
419-
convertAction(
420-
{},
421-
// @ts-expect-error FIXME: Something is wrong here
422-
v.minValue<unknown, 3>(3),
423-
{ force: true }
424-
)
345+
convertAction({}, v.minValue<v.ValueInput, 3>(3), { force: true })
425346
).toStrictEqual({
426347
minimum: 3,
427348
});
428349
expect(console.warn).toHaveBeenLastCalledWith(
429350
'The "min_value" action is not supported on type "undefined".'
430351
);
431352
expect(
432-
convertAction(
433-
{ type: 'string' },
434-
// @ts-expect-error FIXME: Something is wrong here
435-
v.minValue<string, 3>(3),
436-
{ force: true }
437-
)
353+
convertAction({ type: 'string' }, v.minValue<v.ValueInput, 3>(3), {
354+
force: true,
355+
})
438356
).toStrictEqual({ type: 'string', minimum: 3 });
439357
expect(console.warn).toHaveBeenLastCalledWith(
440358
'The "min_value" action is not supported on type "string".'
@@ -506,8 +424,7 @@ describe('convertAction', () => {
506424
expect(
507425
convertAction(
508426
{ type: 'boolean' },
509-
// @ts-expect-error FIXME: Something is wrong here
510-
v.value<boolean, true>(true),
427+
v.value<v.ValueInput, true>(true),
511428
undefined
512429
)
513430
).toStrictEqual({
@@ -517,8 +434,7 @@ describe('convertAction', () => {
517434
expect(
518435
convertAction(
519436
{ type: 'number' },
520-
// @ts-expect-error FIXME: Something is wrong here
521-
v.value<boolean, 123>(123),
437+
v.value<v.ValueInput, 123>(123),
522438
undefined
523439
)
524440
).toStrictEqual({
@@ -528,8 +444,7 @@ describe('convertAction', () => {
528444
expect(
529445
convertAction(
530446
{ type: 'string' },
531-
// @ts-expect-error FIXME: Something is wrong here
532-
v.value<string, 'foo'>('foo'),
447+
v.value<v.ValueInput, 'foo'>('foo'),
533448
undefined
534449
)
535450
).toStrictEqual({

0 commit comments

Comments
 (0)