Repository navigation
Negated Types: Define Extract and Exclude in terms of intersections and negations - #64515
Wesley Wigham (weswigham) wants to merge 2 commits into
Conversation
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; |
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.
a85d8ae to
594cbf6
Compare
594cbf6 to
67cadab
Compare
67cadab to
7b2ace0
Compare
7b2ace0 to
5d931b8
Compare
|
TypeScript Bot (@typescript-bot) test this |
|
Hey Wesley Wigham (@weswigham), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
|
Hey Wesley Wigham (@weswigham), here are more DT test results: Branch only errors:
|
|
Hey Wesley Wigham (@weswigham), here are more DT test results: Branch only errors:
|
|
Hey Wesley Wigham (@weswigham), here are more DT test results: Branch only errors:
|
|
Hey Wesley Wigham (@weswigham), here are more DT test results: Branch only errors:
|
|
TypeScript Bot (@typescript-bot) pack this |
|
Hey, Wesley Wigham (@weswigham)! I've packed 5d931b8 into an installable package. You can install it for testing by referencing it in your {
"devDependencies": {
"typescript": "npm:@typescript-deploys/pr-build@7.1.0-pr.64515.5"
}
}and then running There is also a playground for this build. |
|
Wesley Wigham (@weswigham) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Experiment done, work will continue in #64375 - this breaks soooooo much with the second type leaking into the output in |
|
Wesley Wigham (@weswigham) Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Details
|
|
Wesley Wigham (@weswigham) Here are some more interesting changes from running the user tests suite Details
|
|
Wesley Wigham (@weswigham) Here are some more interesting changes from running the user tests suite Details
|
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.