GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Improve checking of complex rest parameter types by ahejlsberg · Pull Request #26676 · microsoft/TypeScript Conversation
Member
With this PR we properly check rest parameters of any subtype of declare const foo: (x: string, ...args: [string] | [number, boolean]) => void; declare const t: [string] | [number, boolean]; foo("abc", "def"); // Ok foo("abc", 10, true); // Ok foo("abc", ...t); // Ok foo("abc", 10); // Error, [number] not assignable to [string] | [number, boolean] foo("abc"); // Error, [] not assignable to [string] | [number, boolean] Effectively, rest parameters typed as unions of tuple types provide a form of overloading expressed in a single function type signature. Unlike regular overloading, generic rest parameters can be used to form composed overloads: type Func<T extends any[]> = (x: string, ...args: T) => void; declare const f: Func<[] | [string] | [number, ...boolean[]]>; f("abc"); f("abc", "def"); f("abc", 10); f("abc", 10, true); f("abc", 10, true, false); f(); // Error f("abc", true); // Error Function type relations have been improved to handle rest parameters of union types: declare let f1: (x: string, ...args: [string] | [number, boolean]) => void; declare let f2: (x: string, y: string) => void; declare let f3: (x: string, y: number, z: boolean) => void; declare let f4: (...args: [string, string] | [string, number, boolean]) => void; f2 = f1; // Ok f3 = f1; // Ok f4 = f1; // Error, misaligned complex rest types f1 = f2; // Error f1 = f3; // Error f1 = f4; // Error, misaligned complex rest types Note that we currently don't "normalize" misaligned rest parameters. It would certainly be possible to do so, but it is not clear that the additional complexity is merited.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
Nathan Shively-Sanders (sandersn)
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the change. Just a few nits in the code.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo:misaligned
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is only used in
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it where it is, it is closely related to the function just above.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort of agree, but the rewrite you suggest doesn't work because it injects a
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
9 tasks done
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |