Skip to content

Conversation

@som-sm
Copy link
Contributor

@som-sm som-sm commented Jun 12, 2025

PR Checklist

  • Addresses an existing open issue: related to #000
  • Steps in Contributing were taken

Overview

Currently, IsTuple doesn’t recognise arrays with a rest element and optional elements as tuples, such as [number?, …string[]].

import { IsTuple } from 'ts-essentials';

type T = IsTuple<[number?, ...string[]]>;
//   ^? type T = never

This PR fixes that by updating the implementation of IsTuple.


However, the above fix causes the following test to fail in DeepNullable (similar with DeepUndefinable):

Assert<IsExact<DeepNullable<never[]>, null[]>>

There are two problems here:

  1. Incorrect behavior in IsTuple for never[]:
    Previously, IsTuple<never[]> returned never[], which is incorrect—it should return never. The updated implementation corrects this.

  2. Incorrect handling of never in DeepNullable:
    Once IsTuple<never[]> correctly returns never, DeepNullable<never[]> starts returning never[] instead of null[]. This happens because DeepNullable<never> currently returns never.

    The issue becomes more apparent when testing with a case that doesn't involve IsTuple:

    type T = DeepNullable<{ foo: never }>;
    //    ^? { foo: never } (expected: { foo: null })

    To fix this, this PR makes DeepNullable<never> return null.

@som-sm som-sm force-pushed the fix/is-tuple-with-arrays-with-rest branch 2 times, most recently from 8c47bba to c6f6999 Compare June 13, 2025 08:00
@som-sm som-sm force-pushed the fix/is-tuple-with-arrays-with-rest branch 2 times, most recently from 213bbb9 to a51a618 Compare June 13, 2025 09:54
@som-sm som-sm force-pushed the fix/is-tuple-with-arrays-with-rest branch from a51a618 to 09179c1 Compare June 13, 2025 10:32
@som-sm som-sm force-pushed the fix/is-tuple-with-arrays-with-rest branch from 090bf04 to 6192049 Compare June 13, 2025 10:43
@som-sm som-sm marked this pull request as ready for review June 13, 2025 10:44
@Beraliv
Copy link
Collaborator

Beraliv commented Jun 13, 2025

Hey @som-sm ! Thank you for raising the PR, I'll check it later today or on the weekend

Copy link
Collaborator

@Beraliv Beraliv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @som-sm! Thank you for raising this PR

@Beraliv Beraliv merged commit 16e427d into ts-essentials:master Jun 16, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants