{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13126","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13126/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13126/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13126/events","html_url":"https://github.com/Microsoft/TypeScript/issues/13126","id":197208176,"number":13126,"title":"Empty tuple type now meaningful (at least, in unions)","user":{"login":"krryan","id":6392679,"avatar_url":"https://avatars2.githubusercontent.com/u/6392679?v=4","gravatar_id":"","url":"https://api.github.com/users/krryan","html_url":"https://github.com/krryan","followers_url":"https://api.github.com/users/krryan/followers","following_url":"https://api.github.com/users/krryan/following{/other_user}","gists_url":"https://api.github.com/users/krryan/gists{/gist_id}","starred_url":"https://api.github.com/users/krryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krryan/subscriptions","organizations_url":"https://api.github.com/users/krryan/orgs","repos_url":"https://api.github.com/users/krryan/repos","events_url":"https://api.github.com/users/krryan/events{/privacy}","received_events_url":"https://api.github.com/users/krryan/received_events","type":"User","site_admin":false},"labels":[{"id":117630704,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Accepting%20PRs","name":"Accepting PRs","color":"009800","default":false},{"id":113971155,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/2","html_url":"https://github.com/Microsoft/TypeScript/milestone/2","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/2/labels","id":721044,"number":2,"title":"Community","description":"Issues in the 'Community' milestone are ones which we are accepting pull requests for","creator":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars3.githubusercontent.com/u/6685088?v=4","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"open_issues":308,"closed_issues":121,"state":"open","created_at":"2014-07-14T23:24:58Z","updated_at":"2017-08-28T20:45:11Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2016-12-22T16:09:11Z","updated_at":"2017-08-28T20:52:14Z","closed_at":null,"body":"I have a situation where the only valid states for a property are `[]`, `[A]`, or `[A, B, B]`, so I would like to define that property as `[] | [A] | [A, B, B]`. But this gives the error \"A tuple element list cannot be empty,\" and indeed I see that there were a few prior issues relating to the compiler having (incorrectly) allowed it in the past. It seems to me that now, between overloading and unions, this type is useful. Also useful in a typeguard: `isEmpty<A>(values: A[]): values is [] { return values.length === 0; }`\r\n\r\nI suppose the most difficult part of it would be actually tracking that a given array is empty, so that it could be matched against that definition.\r\n\r\nPer the checklist, the grammar is simple enough, `[]` in type positions, shouldn't have any issues with respect to JavaScript. I don't foresee any semantic issues except the above bit about actually recognizing empty arrays as such. The emit isn't affected at all, and compatibility shouldn't be an issue. I'm not rightly sure about the concerns raised in the Other section."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/325477841","html_url":"https://github.com/Microsoft/TypeScript/issues/13126#issuecomment-325477841","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13126","id":325477841,"user":{"login":"gcnew","id":4066840,"avatar_url":"https://avatars1.githubusercontent.com/u/4066840?v=4","gravatar_id":"","url":"https://api.github.com/users/gcnew","html_url":"https://github.com/gcnew","followers_url":"https://api.github.com/users/gcnew/followers","following_url":"https://api.github.com/users/gcnew/following{/other_user}","gists_url":"https://api.github.com/users/gcnew/gists{/gist_id}","starred_url":"https://api.github.com/users/gcnew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gcnew/subscriptions","organizations_url":"https://api.github.com/users/gcnew/orgs","repos_url":"https://api.github.com/users/gcnew/repos","events_url":"https://api.github.com/users/gcnew/events{/privacy}","received_events_url":"https://api.github.com/users/gcnew/received_events","type":"User","site_admin":false},"created_at":"2017-08-28T20:52:14Z","updated_at":"2017-08-28T20:52:14Z","body":"If tuples have a length property, they will be assignable to `ArrayLike`.\r\n\r\n```ts\r\ntype Tuple2<A, B> = { 0: A, 1: B, length: 2 }\r\n\r\ndeclare function mkTuple2<A, B>(a: A, B: B): Tuple2<A, B>;\r\ndeclare function useArrayLike<T>(x: ArrayLike<T>): void;\r\n\r\nuseArrayLike(mkTuple2(1, 'hello'));\r\n```\r\n\r\nOn the other hand, an exact `length` type will make `Tuple3` not assignable to `Tuple2`, which depending on the use-case might be a good or a bad thing.\r\n\r\nTo be honest, I haven't thought over all consequences and edge cases."}}
{"actor":{"display_login":"gcnew"}}