diff --git a/packages/blockchain-link/src/workers/electrum/index.ts b/packages/blockchain-link/src/workers/electrum/index.ts index bc732d36a94..e28d3ae84e8 100644 --- a/packages/blockchain-link/src/workers/electrum/index.ts +++ b/packages/blockchain-link/src/workers/electrum/index.ts @@ -2,6 +2,7 @@ import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors' import { MESSAGES, RESPONSES } from '@trezor/blockchain-link-types/src/constants'; import type { Response } from '@trezor/blockchain-link-types'; import { Message } from '@trezor/blockchain-link-types/src/messages'; +import { Without } from '@trezor/type-utils'; import { BaseWorker, CONTEXT, ContextType } from '../baseWorker'; import * as M from './methods'; @@ -13,9 +14,6 @@ import type { ElectrumClient } from './client/electrum'; type BlockListener = ReturnType; type TxListener = ReturnType; -// reason: -// https://stackoverflow.com/questions/57103834/typescript-omit-a-property-from-all-interfaces-in-a-union-but-keep-the-union-s#answer-57103940 -type Without = T extends any ? Omit : never; type Request = T extends any ? T & ContextType & { blockListener: BlockListener; txListener: TxListener } : never; diff --git a/packages/type-utils/src/array.ts b/packages/type-utils/src/array.ts new file mode 100644 index 00000000000..8c37cb8f070 --- /dev/null +++ b/packages/type-utils/src/array.ts @@ -0,0 +1,10 @@ +/** + * Gets the type of the elements in an array. + * + * Example: + * ``` + * type A = (number | string)[]; + * type E = ArrayElement; // number | string + * ``` + */ +export type ArrayElement = ArrayType[number]; diff --git a/packages/type-utils/src/index.ts b/packages/type-utils/src/index.ts index 5f0d9cd5fd7..c029bb02a64 100644 --- a/packages/type-utils/src/index.ts +++ b/packages/type-utils/src/index.ts @@ -1,2 +1,5 @@ -export * from './utils'; +export * from './array'; +export * from './overloads'; export * from './timeout'; +export * from './utils'; +export * from './object'; diff --git a/packages/type-utils/src/object.ts b/packages/type-utils/src/object.ts new file mode 100644 index 00000000000..1f18d908681 --- /dev/null +++ b/packages/type-utils/src/object.ts @@ -0,0 +1,13 @@ +export type GetObjectWithKey = U extends object + ? K extends keyof U + ? U + : never + : never; + +export type GetObjectWithoutKey = U extends object + ? K extends keyof U + ? never + : U + : never; + +export type ObjectsOnly = T extends Record ? T : never; diff --git a/packages/type-utils/src/overloads.ts b/packages/type-utils/src/overloads.ts new file mode 100644 index 00000000000..f8f47579dc2 --- /dev/null +++ b/packages/type-utils/src/overloads.ts @@ -0,0 +1,733 @@ +export type OverloadImplementations = Overloads; + +export type Overloads = Overloads24; + +type Overloads24 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; + (...args: infer A20): infer R20; + (...args: infer A21): infer R21; + (...args: infer A22): infer R22; + (...args: infer A23): infer R23; + (...args: infer A24): infer R24; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + (...args: A20) => R20, + (...args: A21) => R21, + (...args: A22) => R22, + (...args: A23) => R23, + (...args: A24) => R24, + ] + : Overloads23; + +type Overloads23 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; + (...args: infer A20): infer R20; + (...args: infer A21): infer R21; + (...args: infer A22): infer R22; + (...args: infer A23): infer R23; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + (...args: A20) => R20, + (...args: A21) => R21, + (...args: A22) => R22, + (...args: A23) => R23, + ] + : Overloads22; + +type Overloads22 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; + (...args: infer A20): infer R20; + (...args: infer A21): infer R21; + (...args: infer A22): infer R22; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + (...args: A20) => R20, + (...args: A21) => R21, + (...args: A22) => R22, + ] + : Overloads21; + +type Overloads21 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; + (...args: infer A20): infer R20; + (...args: infer A21): infer R21; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + (...args: A20) => R20, + (...args: A21) => R21, + ] + : Overloads20; + +type Overloads20 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; + (...args: infer A20): infer R20; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + (...args: A20) => R20, + ] + : Overloads19; + +type Overloads19 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; + (...args: infer A19): infer R19; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + (...args: A19) => R19, + ] + : Overloads18; + +type Overloads18 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; + (...args: infer A18): infer R18; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + (...args: A18) => R18, + ] + : Overloads17; + +type Overloads17 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; + (...args: infer A17): infer R17; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + (...args: A17) => R17, + ] + : Overloads16; + +type Overloads16 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; + (...args: infer A16): infer R16; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + (...args: A16) => R16, + ] + : Overloads15; + +type Overloads15 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; + (...args: infer A15): infer R15; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + (...args: A15) => R15, + ] + : Overloads14; + +type Overloads14 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; + (...args: infer A14): infer R14; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + (...args: A14) => R14, + ] + : Overloads13; + +type Overloads13 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; + (...args: infer A13): infer R13; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + (...args: A13) => R13, + ] + : Overloads12; + +type Overloads12 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; + (...args: infer A12): infer R12; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + (...args: A12) => R12, + ] + : Overloads11; + +type Overloads11 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; + (...args: infer A11): infer R11; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + (...args: A11) => R11, + ] + : Overloads10; + +type Overloads10 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; + (...args: infer A10): infer R10; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + (...args: A10) => R10, + ] + : Overloads9; + +type Overloads9 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; + (...args: infer A9): infer R9; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + (...args: A9) => R9, + ] + : Overloads8; + +type Overloads8 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; + (...args: infer A8): infer R8; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + (...args: A8) => R8, + ] + : Overloads7; + +type Overloads7 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; + (...args: infer A7): infer R7; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + (...args: A7) => R7, + ] + : Overloads6; + +type Overloads6 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; + (...args: infer A6): infer R6; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + (...args: A6) => R6, + ] + : Overloads5; + +type Overloads5 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; + (...args: infer A5): infer R5; +} + ? [ + (...args: A1) => R1, + (...args: A2) => R2, + (...args: A3) => R3, + (...args: A4) => R4, + (...args: A5) => R5, + ] + : Overloads4; + +type Overloads4 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; + (...args: infer A4): infer R4; +} + ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] + : Overloads3; + +type Overloads3 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; + (...args: infer A3): infer R3; +} + ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] + : Overloads2; + +type Overloads2 = T extends { + (...args: infer A1): infer R1; + (...args: infer A2): infer R2; +} + ? [(...args: A1) => R1, (...args: A2) => R2] + : Overloads1; + +type Overloads1 = T extends { + (...args: infer A1): infer R1; +} + ? [(...args: A1) => R1] + : unknown; diff --git a/packages/type-utils/src/utils.ts b/packages/type-utils/src/utils.ts index 11e814f1edb..6222560cef1 100644 --- a/packages/type-utils/src/utils.ts +++ b/packages/type-utils/src/utils.ts @@ -1,20 +1,55 @@ -// make key required - +/** + * Make property of the object required. + * + * Example: + * ``` + * type T = { a?: number }; + * const t: RequiredKey = { a: 0 }; // 'a' is mandatory + * ``` + */ export type RequiredKey = Omit & Required>; -// object values types +/** + * Get type of the object values. + * + * Example: + * ``` + * type T = { a: number; b: string }; + * type V: ObjectValues; // number | string + * ``` + */ export type ObjectValues = T[keyof T]; -// all keys of types in an union +/** + * All keys of types in a union. + * + * Example: + * ``` + * type T = { a: number; b: string }; + * type K: Keys; // 'a' | 'b' + * ``` + */ export type Keys = T extends any ? keyof T : never; -// remove the keys while keeping the union +/** + * Distributes the Omit across a union. using distributive conditional types to achieve this: + * @see: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types + * @source: https://stackoverflow.com/questions/57103834/typescript-omit-a-property-from-all-interfaces-in-a-union-but-keep-the-union-s#answer-57103940 + * + * Example: + * ``` + * type T = { remove: string; keep1: number } | { remove: string; keep2: boolean }; + * type W = Without; + * const w: W = { keep1: 1, keep2: true }; + * ``` + */ export type Without = T extends any ? Omit : never; -// array element type -export type ArrayElement = ArrayType[number]; - -// const with optional types +/** + * Const with optional types. + * Todo: add example and better explanation. + * It has exactly 1 usage so maybe this shall even be here in the utils package + */ export type ConstWithOptionalFields< Const extends { [key: string]: any }, Fields extends string | number | symbol, @@ -30,757 +65,46 @@ export type ConstWithOptionalFields< }; }; -// Extract item from union -export type ItemExtractor = Extract; - -// Unwrap type from Promise -export type Await = T extends { - then(onfulfilled?: (value: infer U) => unknown): unknown; -} - ? U - : T; - +/** + * Recursively makes all properties of the object optional. If the nested property is an object, + * it will make its properties optional as well. + * + * Example: + * ``` + * type T = { a: number; b: { c: string; d: number } }; + * type P = DeepPartial; + * const p: P = { b: { d: 1 } }; // As everything is deeply optional + * ``` + */ export type DeepPartial = T extends () => any ? T : T extends { [key: string]: any } ? { [P in keyof T]?: DeepPartial } : T; +/** + * Type containing all primitive types in TypeScript. + */ export type PrimitiveType = string | number | boolean | Date | null | undefined; -// Record with optional key and required value. -// example of using partial union as keys: -// const p: PartialRecord<'a' | 'b' | 'c', string>; = { b: 'value' }; -export type PartialRecord = { - [P in K]?: T; -}; - -// distributive conditional types to the rescue! This way we can infer union literal type from ReturnType but exclude undefined +/** + * Record with optional key and required value. + * + * Example: + * ``` + * const p: PartialRecord<'a' | 'b' | 'c', string>; = { b: 'value' }; + * ``` + */ +export type PartialRecord = { [P in K]?: T }; + +/** + * This infers the union literal type from ReturnType but exclude undefined + */ export type DefinedUnionMember = T extends string ? T : never; -export type GetObjectWithKey = U extends object - ? K extends keyof U - ? U - : never - : never; -export type GetObjectWithoutKey = U extends object - ? K extends keyof U - ? never - : U - : never; - -export type ObjectsOnly = T extends Record ? T : never; - -// map object `T` to a narrowed type with only those entries that match given `ValueFilter` type +/** + * Map object `T` to a narrowed type with only those entries that match given `ValueFilter` type + */ export type FilterPropertiesByType = { [Key in keyof T as T[Key] extends ValueFilter ? Key : never]: T[Key]; }; - -export type OverloadImplementations = Overloads; -export type Overloads = Overloads24; -type Overloads24 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; - (...args: infer A20): infer R20; - (...args: infer A21): infer R21; - (...args: infer A22): infer R22; - (...args: infer A23): infer R23; - (...args: infer A24): infer R24; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - (...args: A20) => R20, - (...args: A21) => R21, - (...args: A22) => R22, - (...args: A23) => R23, - (...args: A24) => R24, - ] - : Overloads23; -type Overloads23 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; - (...args: infer A20): infer R20; - (...args: infer A21): infer R21; - (...args: infer A22): infer R22; - (...args: infer A23): infer R23; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - (...args: A20) => R20, - (...args: A21) => R21, - (...args: A22) => R22, - (...args: A23) => R23, - ] - : Overloads22; -type Overloads22 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; - (...args: infer A20): infer R20; - (...args: infer A21): infer R21; - (...args: infer A22): infer R22; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - (...args: A20) => R20, - (...args: A21) => R21, - (...args: A22) => R22, - ] - : Overloads21; -type Overloads21 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; - (...args: infer A20): infer R20; - (...args: infer A21): infer R21; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - (...args: A20) => R20, - (...args: A21) => R21, - ] - : Overloads20; -type Overloads20 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; - (...args: infer A20): infer R20; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - (...args: A20) => R20, - ] - : Overloads19; -type Overloads19 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; - (...args: infer A19): infer R19; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - (...args: A19) => R19, - ] - : Overloads18; -type Overloads18 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; - (...args: infer A18): infer R18; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - (...args: A18) => R18, - ] - : Overloads17; -type Overloads17 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; - (...args: infer A17): infer R17; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - (...args: A17) => R17, - ] - : Overloads16; -type Overloads16 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; - (...args: infer A16): infer R16; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - (...args: A16) => R16, - ] - : Overloads15; -type Overloads15 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; - (...args: infer A15): infer R15; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - (...args: A15) => R15, - ] - : Overloads14; -type Overloads14 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; - (...args: infer A14): infer R14; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - (...args: A14) => R14, - ] - : Overloads13; -type Overloads13 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; - (...args: infer A13): infer R13; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - (...args: A13) => R13, - ] - : Overloads12; -type Overloads12 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; - (...args: infer A12): infer R12; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - (...args: A12) => R12, - ] - : Overloads11; -type Overloads11 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; - (...args: infer A11): infer R11; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - (...args: A11) => R11, - ] - : Overloads10; -type Overloads10 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; - (...args: infer A10): infer R10; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - (...args: A10) => R10, - ] - : Overloads9; -type Overloads9 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; - (...args: infer A9): infer R9; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - (...args: A9) => R9, - ] - : Overloads8; -type Overloads8 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; - (...args: infer A8): infer R8; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - (...args: A8) => R8, - ] - : Overloads7; -type Overloads7 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; - (...args: infer A7): infer R7; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - (...args: A7) => R7, - ] - : Overloads6; -type Overloads6 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; - (...args: infer A6): infer R6; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - (...args: A6) => R6, - ] - : Overloads5; -type Overloads5 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; - (...args: infer A5): infer R5; -} - ? [ - (...args: A1) => R1, - (...args: A2) => R2, - (...args: A3) => R3, - (...args: A4) => R4, - (...args: A5) => R5, - ] - : Overloads4; -type Overloads4 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; - (...args: infer A4): infer R4; -} - ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] - : Overloads3; -type Overloads3 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; - (...args: infer A3): infer R3; -} - ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] - : Overloads2; -type Overloads2 = T extends { - (...args: infer A1): infer R1; - (...args: infer A2): infer R2; -} - ? [(...args: A1) => R1, (...args: A2) => R2] - : Overloads1; -type Overloads1 = T extends { - (...args: infer A1): infer R1; -} - ? [(...args: A1) => R1] - : unknown; diff --git a/packages/utils/src/mergeDeepObject.ts b/packages/utils/src/mergeDeepObject.ts index 58e5bec4a24..879b7048d6a 100644 --- a/packages/utils/src/mergeDeepObject.ts +++ b/packages/utils/src/mergeDeepObject.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-use-before-define */ // code shamelessly stolen from https://github.com/voodoocreation/ts-deepmerge -type TAllKeys = T extends any ? keyof T : never; +import { Keys } from '@trezor/type-utils'; type TIndexValue = T extends any ? K extends keyof T @@ -22,7 +22,7 @@ type TMerged = [T] extends [Array] : [T] extends [TPrimitives] ? T : [T] extends [object] - ? TPartialKeys<{ [K in TAllKeys]: TMerged> }, never> + ? TPartialKeys<{ [K in Keys]: TMerged> }, never> : T; // istanbul ignore next