GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add empty tuple type by lefb766 · Pull Request #14646 · microsoft/TypeScript

Conversation

@lefb766

@lefb766 Nobuhiro Nakamura (lefb766) commented Mar 14, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #13126

Open question: should a non-empty tuple be assignable to []?

People may think it should be, given that you can assign [number, string] to [number].
However, the index signature of [] which is never blocks such assignment.

I think this isn't going to be a problem at least for now before variadic tuples (#5453) lands.
If you need common type of all tuples, you can simply use {}[] or any[].

Is there any other problemic scenario?

Related discussion: #6229

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@msftclas Microsoft Contribution License Agreements (msftclas) added cla-required and removed cla-required labels Mar 14, 2017
@lefb766
Nobuhiro Nakamura (lefb766) force-pushed the empty-tuple branch from f0385d3 to 0e7ffda Compare March 14, 2017 09:25
sandersn
Nathan Shively-Sanders (sandersn) reviewed Mar 16, 2017
View reviewed changes
Comment thread src/compiler/checker.ts Outdated
return !!getPropertyOfType(type, "0") || isEmptyTupleType(type);
}

function isEmptyTupleType(type: Type): boolean {

@sandersn Nathan Shively-Sanders (sandersn) Mar 16, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

you should be to use === directly, so I think you should drop isEmptyTupleType and just add || type === emptyTupleType on line 8914

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts
// Grammar checking
const hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes);
if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) {
grammarErrorOnNode(node, Diagnostics.A_tuple_type_element_list_cannot_be_empty);

@sandersn Nathan Shively-Sanders (sandersn) Mar 16, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You can delete this error from diagnosticsMessages.json since this is the only usage.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sandersn
Nathan Shively-Sanders (sandersn) requested changes Mar 16, 2017
View reviewed changes
Comment thread tests/cases/compiler/tupleTypes.ts
var et0 = et[0]; // never
var et0: never;

et = []; // Ok

@sandersn Nathan Shively-Sanders (sandersn) Mar 16, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

can you add this same check in a new file, something like tupleTypesStrictNullCheck.ts, with the first line // @strictNullChecks: true to turn on strict null checks?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lefb766
Nobuhiro Nakamura (lefb766) force-pushed the empty-tuple branch from 0e7ffda to 61ac5be Compare March 17, 2017 04:08
@lefb766

Nobuhiro Nakamura (lefb766) commented Mar 20, 2017

Copy link
Copy Markdown
Author

Nathan Shively-Sanders (@sandersn) Your comments are already reflected

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gcnew
Marin Marinov (gcnew) reviewed Mar 20, 2017
View reviewed changes
Comment thread src/compiler/checker.ts
if (elementTypes.length) {
return createTupleType(elementTypes);
}
return createTupleType(elementTypes);

@gcnew Marin Marinov (gcnew) Mar 20, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think you should update the createTupleType function to return the emptyTupleType singleton if elementTypes is empty.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lefb766 Nobuhiro Nakamura (lefb766) Mar 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Agreed. We need to make the condition persistent over future updates. A fix is pushed!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sandersn
Nathan Shively-Sanders (sandersn) approved these changes Apr 5, 2017
View reviewed changes

@sandersn Nathan Shively-Sanders (sandersn) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me. Ryan Cavanaugh (@RyanCavanaugh) or Anders Hejlsberg (@ahejlsberg) can you take a look too?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 23, 2017
View reviewed changes
Comment thread src/compiler/checker.ts Outdated

function createTupleType(elementTypes: Type[]) {
function createTupleType(elementTypes: Type[]): TypeReference {
// We have to ensure that we get same instance for empty tuple type,

@mhegazy Mohamed Hegazy (mhegazy) May 23, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

getTupleTypeOfArity caches the resulting tuple type, so not sure why we need special handling here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) suggested changes May 23, 2017
View reviewed changes

@mhegazy Mohamed Hegazy (mhegazy) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

usage of getTupleTypeOfArity should be sufficient

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lefb766
Nobuhiro Nakamura (lefb766) force-pushed the empty-tuple branch from e02dcf3 to 1476eb4 Compare July 7, 2017 16:45
@KiaraGrouwstra
ditch empty tuple check
665f44f
@KiaraGrouwstra kiara (KiaraGrouwstra) mentioned this pull request Aug 13, 2017
allow empty tuple, fixes #13126 #17762
Closed
@KiaraGrouwstra
empty tuple tests all good
03bf0b8
@KiaraGrouwstra

kiara (KiaraGrouwstra) commented Aug 24, 2017

Copy link
Copy Markdown
Contributor

I've made an attempt to revive this PR taking into account the requested changes at #17762.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lefb766

Nobuhiro Nakamura (lefb766) commented Aug 24, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@tycho01 oh, great! but my bad! I left this PR untouched for so long time and was even unnoticed the update on the original issue until today.

I appreciate you reused my code! Thanks!

Just wondering. Are you going to update them further and implement the additional restrictions you mentioned in #13126 (comment) ?
Currently, I'm getting difficulties finding functional update in your PR... looks they are just pure code cleaning and conflict resolution.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KiaraGrouwstra

kiara (KiaraGrouwstra) commented Aug 24, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Nobuhiro Nakamura (@lefb766): right, I hadn't included those in there.

To answer by sub-topic there:

  • known length, fixing Proposal: strict and open-length tuple types #6229: I filed a separate PR for this at Make tuples have known length #17765. The reason I separated them was that adding empty tuples should be uncontroversial (explicitly marked as 'Accepting PRs' at Empty tuple type now meaningful (at least, in unions) #13126), so I didn't wanna lump them with another feature the TS team had so far been silent on.
  • ditch mutating methods: this was part of my original plan for that Make tuples have known length #17765, making a new Tuple interface extending ReadonlyArray with a length property. This caused the project to not compile anymore though, at which point I'd just quickly settled on letting it extend Array instead, as the length was my primary concern. I then got issues about it not seeing my new interface on half of the tests (wth), at which point I opted to just set that length directly from createTupleTypeForArity instead, foregoing the new interface as length had become its sole added feature.
  • no index signature: I wasn't initially convinced of this, largely in fear of breaking more still than at my ReadonlyArray attempt, though I've recently been swayed this change seems a good thing. I guess it means copying ReadonlyArray into a new Tuple interface, similar minus the index. I wish I understood why we have several copies of this interface in lib.d.ts instead of just having them extend one -- if extending is okay, I'd imagine ReadonlyArray could just be extending this Tuple interface to just add its index too.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lefb766

Nobuhiro Nakamura (lefb766) commented Aug 25, 2017

Copy link
Copy Markdown
Author

@tycho01 Thanks for explaining. I see, you have another PR.

It turns out it will be harder to find difference between #17762 and this one if I happen to solve the conflict.
I don't have idea on how to deal with this type of situation. You have?

Your investigation on the sup-topic looks interesting though. Nice work.
I have a few opinion on the topics but it may be irrelevant to write them here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KiaraGrouwstra

kiara (KiaraGrouwstra) commented Aug 25, 2017

Copy link
Copy Markdown
Contributor

Nobuhiro Nakamura (@lefb766): wanna just stick with your PR then? If you follow mhegazy's change you may be done. :)

I'd be interested in your take on the topic, but I think the others in #13126 would be too!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lefb766

Nobuhiro Nakamura (lefb766) commented Aug 26, 2017

Copy link
Copy Markdown
Author

@tycho01 Fair point. I'll continue this work. Sorry for bothering you and others.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Nobuhiro Nakamura (lefb766) added 2 commits August 27, 2017 15:41
@lefb766
Add empty tuple type
bf14cfa
@lefb766
Merge branch 'tycho01:13126-empty-tuple' into empty-tuple
5cffdb2
@lefb766
Nobuhiro Nakamura (lefb766) force-pushed the empty-tuple branch from 1476eb4 to 5cffdb2 Compare August 27, 2017 08:48
@lefb766

Nobuhiro Nakamura (lefb766) commented Aug 27, 2017

Copy link
Copy Markdown
Author

Should be ready for review now. Mohamed Hegazy (@mhegazy) can you take a look?

I've selectively adopted @tycho01 's work.

Note: #6524 can also be closed after merge this PR.

KiaraGrouwstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftgits Microsoft GitHub User (msftgits) removed the cla-signed label Sep 26, 2017
@microsoft Microsoft (microsoft) deleted a comment from Microsoft Contribution License Agreements (msftclas) Sep 26, 2017
@microsoft Microsoft (microsoft) deleted a comment from Microsoft Contribution License Agreements (msftclas) Sep 26, 2017
@KiaraGrouwstra

kiara (KiaraGrouwstra) commented Feb 14, 2018

Copy link
Copy Markdown
Contributor

Mohamed Hegazy (@mhegazy): conflict aside, is there more that could be done to improve this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KiaraGrouwstra kiara (KiaraGrouwstra) mentioned this pull request Jun 12, 2018
Tuples in rest parameters and spread expressions #24897
Merged
@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 18, 2018

Copy link
Copy Markdown
Contributor

Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it.

KiaraGrouwstra reacted with thumbs down emoji KiaraGrouwstra reacted with confused emoji
All reactions
  • 👎 1 reaction
  • 😕 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot TypeScript Bot (typescript-bot) closed this Jun 18, 2018
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sandersn Nathan Shively-Sanders (sandersn) sandersn approved these changes
+2 more reviewers
@gcnew Marin Marinov (gcnew) gcnew left review comments
@mhegazy Mohamed Hegazy (mhegazy) mhegazy requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@lefb766 @KiaraGrouwstra @typescript-bot @sandersn @gcnew @mhegazy @msftclas @msftgits
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.