Skip to content

Empty tuple type #7520

Closed
Closed

Description

According to the specifications (3.8.5), the following two should be illegal. Tuple types should not be empty and there should be no trailing comma. However, the implementation seems to allow them.

var t1 : [];
var t2 : [number,];

If they are to be allowed and the specifications are to be revised, let me suggest that the tuple type be generalized in the same way as array literals are, in JS. E.g.

var t: [, number,, string,,];

where t is a 5-tuple whose 2nd element is a number and whose 4th element is string (the other three are unknown --- any).

Activity

  1. RyanCavanaugh commented on Mar 15, 2016

    @RyanCavanaugh
    Member

    This is what I get when I compile this:

    (1,10): error TS1122: A tuple type element list cannot be empty.
    (2,17): error TS1009: Trailing comma not allowed.

    What version are you running?

  2. nickie commented on Mar 15, 2016

    @nickie
    Author

    Sorry, I should have mentioned this. Version 1.9.0, from a (slightly outdated, 6 days ago) git clone, commit f06423b. It seems that the current version (commit 9f6f871) issues the errors that you mentioned, so it seems to have been fixed in the last 6 days. Sorry about the false alarm.

    On the other hand, I really wouldn't mind allowing these two and adopting the more liberal view of tuple types that I suggested above. I'm leaving this open, in case somebody wants to think about it...

  3. nickie commented on Mar 15, 2016

    @nickie
    Author

    Oops, sorry, I was wrong once again. The problem seems to be still there in the current commit 9f6f871.

  4. RyanCavanaugh commented on Mar 15, 2016

    @RyanCavanaugh
    Member

    I think something's wrong with whatever setup you're using to test this. I'm on the same commit and am seeing the errors.

    If you want to open a separate suggestion for gapped tuple types, please do, but I'd rather not have this issue tracking it since it's logged as if it were a bug.

  5. nickie commented on Mar 16, 2016

    @nickie
    Author

    The issue seems to be more complicated than I thought. My setup seems to be OK (jake runtests completes successfully).

    In fact, I was testing a slightly larger example containing these two lines. With that larger example, there were no errors reported for these two lines, but there were errors in lines following these two. Here's a MWE showing this strange behaviour:

    var t1 : [];
    var t3 : [number,,];
    

    Now (in the current commit 1156141), although both lines are erroneous, only the second one produces an error message:

    binding-patterns.ts(2,18): error TS1110: Type expected.
    
  6. RyanCavanaugh commented on Mar 16, 2016

    @RyanCavanaugh
    Member

    That's normal behavior. When you have a syntax error, we don't issue type errors. A missing entry in a delimited list is a syntax error, but an empty tuple type is a type error (as you can see this distinction is sometimes a bit arbitrary, but it usually makes sense).

    You can see the same behavior e.g.:

    var t1 : [];
    var y = 1 & ; // Syntax error here, so no type error issued on line 1
  7. nickie commented on Mar 16, 2016

    @nickie
    Author

    OK, understood. My mistake then... Issue closed.

  8. locked and limited conversation to collaborators on Jun 19, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions