Negated Types: Define Extract and Exclude in terms of intersections and negations - #64515
Open
Wesley Wigham (weswigham) wants to merge 1 commit into
Open
Wesley Wigham (weswigham) wants to merge 1 commit into
Wesley Wigham (weswigham) wants to merge 1 commit into
Conversation
Copilot started reviewing on behalf of
Wesley Wigham (weswigham)
September 28, 2026 20:22
View session
Wesley Wigham (weswigham)
changed the base branch from
main
to
weswigham/negated-types
September 28, 2026 20:27
Wesley Wigham (weswigham)
added this pull request to stack #64516
September 28, 2026 20:27
Contributor
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
| * Construct the type of values in T that are not in U | ||
| */ | ||
| type Exclude<T, U> = T extends U ? never : T; | ||
| type Exclude<T, U> = T & not U; |
Contributor
There was a problem hiding this comment.
I've played a little bit with something recently and this difference came to my attention:
type S = { kind: "a" | "b"; value: number };
type A = { kind: "a"; value: number };
type B = { kind: "b"; value: number };
type Nested = Exclude<Exclude<S, B>, A>; // { kind: "a" | "b"; value: number; }
type Merged = Exclude<S, A | B>; // neverThis PR "fixes" that - both of those reduce down to never (I've checked). I think this makes more sense for an average user, it makes for an interesting test case so it might be worth adding to this PR.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Swaps
ExtracttoT & UandExcludetoT & not U, instead of their current conditional forms.This isn't a strict improvement - in some ways, it's a step backward. On the extreme end, consider that
Extract<T, any>previously yieldsT, but now yieldsany- the substitution behavior in conditionals hides the type erasureany(top level or nested) performs.