From 62529d20f87c01b315b4b0f10372136942961c8c Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Sun, 15 Sep 2024 12:16:34 -0400 Subject: [PATCH] Investigate, understand and partially resolve TS errors --- .../to-json-schema/src/convertAction.test.ts | 167 +++++------------- .../to-json-schema/src/convertSchema.test.ts | 17 +- 2 files changed, 52 insertions(+), 132 deletions(-) diff --git a/packages/to-json-schema/src/convertAction.test.ts b/packages/to-json-schema/src/convertAction.test.ts index 01d53654e..c09b71ac8 100644 --- a/packages/to-json-schema/src/convertAction.test.ts +++ b/packages/to-json-schema/src/convertAction.test.ts @@ -88,8 +88,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), + v.length(3), undefined ) ).toStrictEqual({ @@ -101,12 +100,7 @@ describe('convertAction', () => { test('should convert length action for arrays', () => { expect( - convertAction( - { type: 'array' }, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), - undefined - ) + convertAction({ type: 'array' }, v.length(3), undefined) ).toStrictEqual({ type: 'array', minItems: 3, @@ -116,18 +110,12 @@ describe('convertAction', () => { test('should throw error for length action with invalid type', () => { expect(() => - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), - undefined - ) + convertAction({}, v.length(3), undefined) ).toThrowError('The "length" action is not supported on type "undefined".'); expect(() => convertAction( { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), + v.length(3), undefined ) ).toThrowError('The "length" action is not supported on type "object".'); @@ -135,12 +123,7 @@ describe('convertAction', () => { test('should force conversion for length action with invalid type', () => { expect( - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), - { force: true } - ) + convertAction({}, v.length(3), { force: true }) ).toStrictEqual({ minLength: 3, maxLength: 3, @@ -149,12 +132,9 @@ describe('convertAction', () => { 'The "length" action is not supported on type "undefined".' ); expect( - convertAction( - { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.length(3), - { force: true } - ) + convertAction({ type: 'object' }, v.length(3), { + force: true, + }) ).toStrictEqual({ type: 'object', minLength: 3, maxLength: 3 }); expect(console.warn).toHaveBeenLastCalledWith( 'The "length" action is not supported on type "object".' @@ -165,8 +145,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), + v.minLength(3), undefined ) ).toStrictEqual({ @@ -179,8 +158,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'array' }, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), + v.minLength(3), undefined ) ).toStrictEqual({ @@ -191,20 +169,14 @@ describe('convertAction', () => { test('should throw error for min length action with invalid type', () => { expect(() => - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), - undefined - ) + convertAction({}, v.minLength(3), undefined) ).toThrowError( 'The "min_length" action is not supported on type "undefined".' ); expect(() => convertAction( { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), + v.minLength(3), undefined ) ).toThrowError( @@ -214,12 +186,7 @@ describe('convertAction', () => { test('should force conversion for min length action with invalid type', () => { expect( - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), - { force: true } - ) + convertAction({}, v.minLength(3), { force: true }) ).toStrictEqual({ minLength: 3, }); @@ -227,12 +194,9 @@ describe('convertAction', () => { 'The "min_length" action is not supported on type "undefined".' ); expect( - convertAction( - { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.minLength(3), - { force: true } - ) + convertAction({ type: 'object' }, v.minLength(3), { + force: true, + }) ).toStrictEqual({ type: 'object', minLength: 3 }); expect(console.warn).toHaveBeenLastCalledWith( 'The "min_length" action is not supported on type "object".' @@ -243,8 +207,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), + v.maxLength(3), undefined ) ).toStrictEqual({ @@ -257,8 +220,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'array' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), + v.maxLength(3), undefined ) ).toStrictEqual({ @@ -269,20 +231,14 @@ describe('convertAction', () => { test('should throw error for max length action with invalid type', () => { expect(() => - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), - undefined - ) + convertAction({}, v.maxLength(3), undefined) ).toThrowError( 'The "max_length" action is not supported on type "undefined".' ); expect(() => convertAction( { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), + v.maxLength(3), undefined ) ).toThrowError( @@ -292,12 +248,7 @@ describe('convertAction', () => { test('should force conversion for max length action with invalid type', () => { expect( - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), - { force: true } - ) + convertAction({}, v.maxLength(3), { force: true }) ).toStrictEqual({ maxLength: 3, }); @@ -305,12 +256,9 @@ describe('convertAction', () => { 'The "max_length" action is not supported on type "undefined".' ); expect( - convertAction( - { type: 'object' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxLength(3), - { force: true } - ) + convertAction({ type: 'object' }, v.maxLength(3), { + force: true, + }) ).toStrictEqual({ type: 'object', maxLength: 3 }); expect(console.warn).toHaveBeenLastCalledWith( 'The "max_length" action is not supported on type "object".' @@ -321,8 +269,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'number' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxValue(3), + v.maxValue(3), undefined ) ).toStrictEqual({ @@ -333,20 +280,14 @@ describe('convertAction', () => { test('should throw error for max value action with invalid type', () => { expect(() => - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.maxValue(3), - undefined - ) + convertAction({}, v.maxValue(3), undefined) ).toThrowError( 'The "max_value" action is not supported on type "undefined".' ); expect(() => convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxValue(3), + v.maxValue(3), undefined ) ).toThrowError('The "max_value" action is not supported on type "string".'); @@ -354,12 +295,7 @@ describe('convertAction', () => { test('should force conversion for max value action with invalid type', () => { expect( - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.maxValue(3), - { force: true } - ) + convertAction({}, v.maxValue(3), { force: true }) ).toStrictEqual({ maximum: 3, }); @@ -367,12 +303,9 @@ describe('convertAction', () => { 'The "max_value" action is not supported on type "undefined".' ); expect( - convertAction( - { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.maxValue(3), - { force: true } - ) + convertAction({ type: 'string' }, v.maxValue(3), { + force: true, + }) ).toStrictEqual({ type: 'string', maximum: 3 }); expect(console.warn).toHaveBeenLastCalledWith( 'The "max_value" action is not supported on type "string".' @@ -383,8 +316,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'number' }, - // @ts-expect-error FIXME: Something is wrong here - v.minValue(3), + v.minValue(3), undefined ) ).toStrictEqual({ @@ -395,20 +327,14 @@ describe('convertAction', () => { test('should throw error for min value action with invalid type', () => { expect(() => - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.minValue(3), - undefined - ) + convertAction({}, v.minValue(3), undefined) ).toThrowError( 'The "min_value" action is not supported on type "undefined".' ); expect(() => convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.minValue(3), + v.minValue(3), undefined ) ).toThrowError('The "min_value" action is not supported on type "string".'); @@ -416,12 +342,7 @@ describe('convertAction', () => { test('should force conversion for min value action with invalid type', () => { expect( - convertAction( - {}, - // @ts-expect-error FIXME: Something is wrong here - v.minValue(3), - { force: true } - ) + convertAction({}, v.minValue(3), { force: true }) ).toStrictEqual({ minimum: 3, }); @@ -429,12 +350,9 @@ describe('convertAction', () => { 'The "min_value" action is not supported on type "undefined".' ); expect( - convertAction( - { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.minValue(3), - { force: true } - ) + convertAction({ type: 'string' }, v.minValue(3), { + force: true, + }) ).toStrictEqual({ type: 'string', minimum: 3 }); expect(console.warn).toHaveBeenLastCalledWith( 'The "min_value" action is not supported on type "string".' @@ -506,8 +424,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'boolean' }, - // @ts-expect-error FIXME: Something is wrong here - v.value(true), + v.value(true), undefined ) ).toStrictEqual({ @@ -517,8 +434,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'number' }, - // @ts-expect-error FIXME: Something is wrong here - v.value(123), + v.value(123), undefined ) ).toStrictEqual({ @@ -528,8 +444,7 @@ describe('convertAction', () => { expect( convertAction( { type: 'string' }, - // @ts-expect-error FIXME: Something is wrong here - v.value('foo'), + v.value('foo'), undefined ) ).toStrictEqual({ diff --git a/packages/to-json-schema/src/convertSchema.test.ts b/packages/to-json-schema/src/convertSchema.test.ts index ff0fb69b9..35dfd466e 100644 --- a/packages/to-json-schema/src/convertSchema.test.ts +++ b/packages/to-json-schema/src/convertSchema.test.ts @@ -200,7 +200,7 @@ describe('convertSchema', () => { expect( convertSchema( {}, - // @ts-expect-error FIXME: Something is wrong here + // @ts-expect-error v.object({ key1: v.string(), key2: v.optional(v.string()), @@ -227,7 +227,7 @@ describe('convertSchema', () => { expect( convertSchema( {}, - // @ts-expect-error FIXME: Something is wrong here + // @ts-expect-error v.objectWithRest( { key1: v.string(), @@ -257,7 +257,7 @@ describe('convertSchema', () => { expect( convertSchema( {}, - // @ts-expect-error FIXME: Something is wrong here + // @ts-expect-error v.looseObject({ key1: v.string(), key2: v.optional(v.string()), @@ -284,7 +284,7 @@ describe('convertSchema', () => { expect( convertSchema( {}, - // @ts-expect-error FIXME: Something is wrong here + // @ts-expect-error v.strictObject({ key1: v.string(), key2: v.optional(v.string()), @@ -537,8 +537,13 @@ describe('convertSchema', () => { KEY4 = 123, } expect( - // @ts-expect-error FIXME: Something is wrong here - convertSchema({}, v.enum(TestEnum), undefined, createContext()) + convertSchema( + {}, + // @ts-expect-error + v.enum(TestEnum), + undefined, + createContext() + ) ).toStrictEqual({ enum: [0, 1, 'foo', 123], });