From 76e6ece55b21394d4d16ed8718b6212e34c3b9cd Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Tue, 3 Oct 2023 09:07:57 -0400 Subject: [PATCH] improve vanilla array handling --- src/index.ts | 14 ++++++++------ test/__snapshots__/errors.test.ts.snap | 5 ++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 90534bf..ad08932 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,12 +54,14 @@ export type UsefulKeys = T extends any[] // This swaps "leaf" types with a literal message about what the actual and expected types are. // Needs to check for Not> because otherwise LeafTypeOf returns never, which extends everything 🤔 export type MismatchInfo = And<[Extends, '...'>, Not>]> extends true - ? { - [K in UsefulKeys | UsefulKeys]: MismatchInfo< - K extends keyof Actual ? Actual[K] : never, - K extends keyof Expected ? Expected[K] : never - > - } + ? And<[Extends, Extends]> extends true + ? Array[number], Extract[number]>> + : { + [K in UsefulKeys | UsefulKeys]: MismatchInfo< + K extends keyof Actual ? Actual[K] : never, + K extends keyof Expected ? Expected[K] : never + > + } : StrictEqualUsingBranding extends true ? Actual : `Expected: ${PrintType}, Actual: ${PrintType>}` diff --git a/test/__snapshots__/errors.test.ts.snap b/test/__snapshots__/errors.test.ts.snap index de54d98..5c2563d 100644 --- a/test/__snapshots__/errors.test.ts.snap +++ b/test/__snapshots__/errors.test.ts.snap @@ -148,9 +148,8 @@ test/usage.test.ts:999:999 - error TS2349: This expression is not callable. 999 expectTypeOf([1, 2, 3]).items.toBeString() ~~~~~~~~~~ -test/usage.test.ts:999:999 - error TS2344: Type 'number[]' does not satisfy the constraint '{ [x: number]: never; }'. - 'number' index signatures are incompatible. - Type 'number' is not assignable to type 'never'. +test/usage.test.ts:999:999 - error TS2344: Type 'number[]' does not satisfy the constraint 'never[]'. + Type 'number' is not assignable to type 'never'. 999 expectTypeOf().toEqualTypeOf() ~~~~~~~~