Skip to content

StrictNull check Tuple overflow #18253

Closed
Closed

Description

TypeScript Version: 2.4.1

Code

const tuple: [string, number] = ["", 0];
const value = tuple[2];

Expected behavior:
Not compiling. You cant define a type based on what is currently define in the array.
This behavior broke the strict null check validation because this value should be undefined or the accessor non legit.

Actual behavior:
Compile and value as the type of all types defined in the tuple, in this case string | number.

Activity

  1. imcotton commented on Sep 5, 2017

    @imcotton
    Contributor

    When accessing an element outside the set of known indices, a union type is used instead

    from: handbook#tuple

  2. sebdoucet commented on Sep 5, 2017

    @sebdoucet
    Author

    Because it's in the hanbook, that does not make more cense to me.

    Why it's not at least a tuple combine with undefined. It broke strict null checking like string | number | undefined

  3. mhegazy commented on Sep 5, 2017

    @mhegazy
    Contributor

    Duplicate of #6229

  4. mhegazy commented on Sep 20, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  5. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions