From 2a2a13d96a443f1b3165d6c43a61fba9e3b019e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Thu, 8 Dec 2022 13:14:27 +0100 Subject: [PATCH] fix(core): remove `readonly` from properties of `FilterQuery` Closes #3836 --- packages/core/src/typings.ts | 2 +- tests/types.test.ts | 39 +++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/core/src/typings.ts b/packages/core/src/typings.ts index c1143990cc14..98f01776998d 100644 --- a/packages/core/src/typings.ts +++ b/packages/core/src/typings.ts @@ -83,7 +83,7 @@ export type FilterValue = OperatorMap> | FilterValue2 | Fi type ExpandObject = T extends object ? T extends Scalar ? never - : { [K in keyof T as ExcludeFunctions]?: Query> | FilterValue> | null } + : { -readonly [K in keyof T as ExcludeFunctions]?: Query> | FilterValue> | null } : never; export type Query = T extends object diff --git a/tests/types.test.ts b/tests/types.test.ts index 4f62709c4e8a..99a0e0c6a4e4 100644 --- a/tests/types.test.ts +++ b/tests/types.test.ts @@ -151,7 +151,7 @@ describe('check typings', () => { }); test('Query', async () => { - // assert, Date>>(true); + assert, Date>>(true); assert, number>>(false); // assert, string>>(true); assert, { born?: Date }>>(true); @@ -292,6 +292,38 @@ describe('check typings', () => { const baz = compositeRef.baz; }); + test('ObjectQuery with readonly properties (#3836)', async () => { + interface Publisher { + readonly id: string; + readonly name: string; + } + interface User { + readonly id: number; + readonly name: string; + readonly age?: number; + readonly born?: Date; + readonly rel?: Publisher; + readonly relRef?: Reference; + readonly relIdRef?: IdentifiedReference; + readonly rels?: Collection; + } + + let ok01: FilterQuery; + ok01 = {}; + ok01 = { name: 'foo' }; + ok01 = { born: { $gte: new Date() } }; + ok01 = { age: { $gte: 1 } }; + ok01 = { age: 1 }; + ok01 = { rel: 'abc' }; + ok01 = { rel: ['abc'] }; + ok01 = { relRef: 'abc' }; + ok01 = { relRef: ['abc'] }; + ok01 = { relIdRef: 'abc' }; + ok01 = { relIdRef: ['abc'] }; + ok01 = { rels: 'abc' }; + ok01 = { rels: ['abc'] }; + }); + test('AutoPath with optional nullable properties', async () => { interface MessageRecipient { id: string; @@ -345,12 +377,13 @@ describe('check typings', () => { bar = null; }); - test('FilterQueryOrPrimary ok assignments', async () => { + test('FilterQuery ok assignments', async () => { let ok01: FilterQuery; ok01 = {}; ok01 = { born: new Date() }; ok01 = { born: { $gte: new Date() } }; ok01 = { age: { $gte: 1 } }; + ok01 = { age: 1 }; ok01 = { favouriteBook: '1' }; ok01 = { favouriteBook: ['1', '2'] }; ok01 = { favouriteBook: null }; @@ -397,7 +430,7 @@ describe('check typings', () => { ok07.$or = [{ name: '231' }]; }); - test('FilterQueryOrPrimary bad assignments', async () => { + test('FilterQuery bad assignments', async () => { let fail01: FilterQuery; // @ts-expect-error fail01 = { born: 123 };