From 9c858729efc68eb67df82f7e99794017c8ba8b55 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Thu, 29 Sep 2022 18:04:55 +0400 Subject: [PATCH 1/3] Fix DeepPartial type --- js/core/index.d.ts | 7 ++++--- ts/dx.all.d.ts | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/core/index.d.ts b/js/core/index.d.ts index 5eea3d9c9b4..c5d0a603569 100644 --- a/js/core/index.d.ts +++ b/js/core/index.d.ts @@ -19,9 +19,10 @@ export type Xor> | Seal>; -export type DeepPartial = T extends object ? { - [P in keyof T]?: T[P] extends Function ? T[P] : DeepPartial; -} : T; +type Scalar = string | number | Function | Date | Boolean | Array; +export type DeepPartial = T extends Scalar ? T : { + [P in keyof T]?: DeepPartial; +}; type ItemType = T extends (infer TItem)[] ? TItem : T; type Property = T extends Partial> ? TValue : never; diff --git a/ts/dx.all.d.ts b/ts/dx.all.d.ts index 441f7b938e6..11d652a77a7 100644 --- a/ts/dx.all.d.ts +++ b/ts/dx.all.d.ts @@ -1676,11 +1676,11 @@ declare module DevExpress.core { /** * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */ - export type DeepPartial = T extends object - ? { - [P in keyof T]?: T[P] extends Function ? T[P] : DeepPartial; - } - : T; + export type DeepPartial = T extends Scalar + ? T + : { + [P in keyof T]?: DeepPartial; + }; export type DefaultOptionsRule = { device?: Device | Device[] | ((device: Device) => boolean); options: DeepPartial; @@ -1757,6 +1757,10 @@ declare module DevExpress.core { * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */ interface PromiseType extends JQueryPromise {} + /** + * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. + */ + type Scalar = string | number | Function | Date | Boolean | Array; /** * [descr:template] */ From 075870fae19413e0bcf8e81133026b5ff3ba9273 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Fri, 30 Sep 2022 14:58:55 +0400 Subject: [PATCH 2/3] Add more scalar types --- js/core/index.d.ts | 2 +- testing/typescript/core.ts | 229 +++++++++++++++++++++---------------- 2 files changed, 134 insertions(+), 97 deletions(-) diff --git a/js/core/index.d.ts b/js/core/index.d.ts index c5d0a603569..758ae06028e 100644 --- a/js/core/index.d.ts +++ b/js/core/index.d.ts @@ -19,7 +19,7 @@ export type Xor> | Seal>; -type Scalar = string | number | Function | Date | Boolean | Array; +export type Scalar = undefined | null | string | String | number | Number | bigint | BigInteger | boolean | Boolean | Date | Function | Symbol | Array; export type DeepPartial = T extends Scalar ? T : { [P in keyof T]?: DeepPartial; }; diff --git a/testing/typescript/core.ts b/testing/typescript/core.ts index 1e80a61289e..de7ed15a1c8 100644 --- a/testing/typescript/core.ts +++ b/testing/typescript/core.ts @@ -1,107 +1,144 @@ +/* eslint-disable import/no-duplicates */ +/* eslint-disable import/first */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-type-alias */ -import { - PropertyType, -} from '../../js/core'; +/* eslint-disable @typescript-eslint/consistent-type-definitions */ +/* eslint-disable @typescript-eslint/ban-types */ +/* eslint-disable no-inner-declarations */ import { assertType, toAssertion, } from './consts'; -type ComplexType = { - a: { - b?: number | { - c: boolean; - }; +import { Scalar } from '../../js/core'; + +{ + interface TestInterface { i: any } + class TestClass { c: any; } + type TestType = { t: any }; + function testFunction() {} + + const scalar1: String extends Scalar ? true : false = true; + const scalar2: string extends Scalar ? true : false = true; + const scalar3: number extends Scalar ? true : false = true; + const scalar4: Number extends Scalar ? true : false = true; + const scalar5: bigint extends Scalar ? true : false = true; + const scalar6: BigInteger extends Scalar ? true : false = true; + const scalar7: Date extends Scalar ? true : false = true; + const scalar8: boolean extends Scalar ? true : false = true; + const scalar9: Boolean extends Scalar ? true : false = true; + const scalar10: null extends Scalar ? true : false = true; + const scalar11: undefined extends Scalar ? true : false = true; + const scalar12: Symbol extends Scalar ? true : false = true; + const scalar13: [] extends Scalar ? true : false = true; + const scalar14: (() => {}) extends Scalar ? true : false = true; + const scalar15: typeof testFunction extends Scalar ? true : false = true; + const scalar16: Symbol extends Scalar ? true : false = true; + + const nonScalar1: TestInterface extends Scalar ? true : false = false; + const nonScalar2: TestClass extends Scalar ? true : false = false; + const nonScalar3: TestType extends Scalar ? true : false = false; + const nonScalar4: object extends Scalar ? true : false = false; +} + +import { PropertyType } from '../../js/core'; + +{ + type ComplexType = { + a: { + b?: number | { + c: boolean; + }; + x: number; + } | { e: string }; + } + | string + | { + d: boolean | string; + f: string | { + g: number | Record; + }[]; + }; + + type AExpected = { + b?: BExpected; x: number; } | { e: string }; + type BExpected = number | { c: boolean }; + type FExpected = string | { g: GExpected }[]; + type GExpected = number | Record; + + const a1: AExpected = { + e: 'e', + }; + const a2: AExpected = { + x: 42, + }; + const a3: AExpected = { + x: 42, + b: 1, + }; + const a4: AExpected = { + x: 42, + b: { + c: false, + }, + }; + + assertType(toAssertion(a1)); + assertType>(toAssertion(a1)); + assertType(toAssertion(a2)); + assertType>(toAssertion(a2)); + assertType(toAssertion(a3)); + assertType>(toAssertion(a3)); + assertType(toAssertion(a4)); + assertType>(toAssertion(a4)); + + const b1: BExpected = 42; + const b2: BExpected = { c: false }; + assertType(toAssertion(b1)); + assertType>(toAssertion(b1)); + assertType, 'b'>>(toAssertion(b1)); + assertType(toAssertion(b2)); + assertType>(toAssertion(b2)); + assertType, 'b'>>(toAssertion(b2)); + + assertType(toAssertion(false)); + assertType>(toAssertion(false)); + assertType < PropertyType, 'b'>, 'c'>>(toAssertion(false)); + assertType(toAssertion(true)); + assertType>(toAssertion(true)); + assertType < PropertyType, 'b'>, 'c'>>(toAssertion(true)); + + assertType(toAssertion(true)); + assertType>(toAssertion(true)); + assertType(toAssertion(false)); + assertType>(toAssertion(false)); + assertType(toAssertion('some string')); + assertType>(toAssertion('some string')); + + assertType(toAssertion('some string')); + assertType>(toAssertion('some string')); + assertType, 'e'>>(toAssertion('some string')); + + const f1: FExpected = 'some string'; + const f2: FExpected = [{ g: 42 }]; + const f3: FExpected = [{ g: { 1: false, 2: false, 3: true } }]; + + assertType(toAssertion(f1)); + assertType>(toAssertion(f1)); + assertType(toAssertion(f2)); + assertType>(toAssertion(f2)); + assertType(toAssertion(f3)); + assertType>(toAssertion(f3)); + + const g1: GExpected = 42; + const g2: GExpected = { 1: false, 2: false, 3: true }; + assertType(toAssertion(g1)); + assertType>(toAssertion(g1)); + assertType, 'g'>>(toAssertion(g1)); + assertType(toAssertion(g2)); + assertType>(toAssertion(g2)); + assertType, 'g'>>(toAssertion(g2)); } -| string -| { - d: boolean | string; - f: string | { - g: number | Record; - }[]; -}; - -type AExpected = { - b?: BExpected; - x: number; -} | { e: string }; -type BExpected = number | { c: boolean }; -type FExpected = string | { g: GExpected }[]; -type GExpected = number | Record; - -const a1: AExpected = { - e: 'e', -}; -const a2: AExpected = { - x: 42, -}; -const a3: AExpected = { - x: 42, - b: 1, -}; -const a4: AExpected = { - x: 42, - b: { - c: false, - }, -}; - -assertType(toAssertion(a1)); -assertType>(toAssertion(a1)); -assertType(toAssertion(a2)); -assertType>(toAssertion(a2)); -assertType(toAssertion(a3)); -assertType>(toAssertion(a3)); -assertType(toAssertion(a4)); -assertType>(toAssertion(a4)); - -const b1: BExpected = 42; -const b2: BExpected = { c: false }; -assertType(toAssertion(b1)); -assertType>(toAssertion(b1)); -assertType, 'b'>>(toAssertion(b1)); -assertType(toAssertion(b2)); -assertType>(toAssertion(b2)); -assertType, 'b'>>(toAssertion(b2)); - -assertType(toAssertion(false)); -assertType>(toAssertion(false)); -assertType < PropertyType, 'b'>, 'c'>>(toAssertion(false)); -assertType(toAssertion(true)); -assertType>(toAssertion(true)); -assertType < PropertyType, 'b'>, 'c'>>(toAssertion(true)); - -assertType(toAssertion(true)); -assertType>(toAssertion(true)); -assertType(toAssertion(false)); -assertType>(toAssertion(false)); -assertType(toAssertion('some string')); -assertType>(toAssertion('some string')); - -assertType(toAssertion('some string')); -assertType>(toAssertion('some string')); -assertType, 'e'>>(toAssertion('some string')); - -const f1: FExpected = 'some string'; -const f2: FExpected = [{ g: 42 }]; -const f3: FExpected = [{ g: { 1: false, 2: false, 3: true } }]; - -assertType(toAssertion(f1)); -assertType>(toAssertion(f1)); -assertType(toAssertion(f2)); -assertType>(toAssertion(f2)); -assertType(toAssertion(f3)); -assertType>(toAssertion(f3)); - -const g1: GExpected = 42; -const g2: GExpected = { 1: false, 2: false, 3: true }; -assertType(toAssertion(g1)); -assertType>(toAssertion(g1)); -assertType, 'g'>>(toAssertion(g1)); -assertType(toAssertion(g2)); -assertType>(toAssertion(g2)); -assertType, 'g'>>(toAssertion(g2)); From d10a87d347325ad624183d7a0575fc56ce5c9e90 Mon Sep 17 00:00:00 2001 From: ilyakhd <14272298+IlyaKhD@users.noreply.github.com> Date: Fri, 30 Sep 2022 15:18:22 +0400 Subject: [PATCH 3/3] Update dx.all.d.ts --- ts/dx.all.d.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ts/dx.all.d.ts b/ts/dx.all.d.ts index 11d652a77a7..dc34a97ae8a 100644 --- a/ts/dx.all.d.ts +++ b/ts/dx.all.d.ts @@ -1760,7 +1760,21 @@ declare module DevExpress.core { /** * @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution. */ - type Scalar = string | number | Function | Date | Boolean | Array; + export type Scalar = + | undefined + | null + | string + | String + | number + | Number + | bigint + | BigInteger + | boolean + | Boolean + | Date + | Function + | Symbol + | Array; /** * [descr:template] */