-
Notifications
You must be signed in to change notification settings - Fork 13k
Port microsoft/typescript-go#1757 #62501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@typescript-bot test it |
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.
Pull Request Overview
This PR ports a fix from the TypeScript Go repository (#1757) that addresses discriminated union type handling when discriminants are missing. The change modifies the discriminated union logic to better handle cases where union members lack discriminant properties.
Key Changes
- Modified discriminant property checking logic in the type checker
- Simplified conditional structure by combining null and literal type checks
- Added test case demonstrating the fixed behavior with missing discriminants
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/compiler/checker.ts |
Simplifies discriminant validation logic by combining discriminant existence and literal type checks |
tests/cases/compiler/missingDiscriminants2.ts |
Adds test case with union types having missing discriminant properties |
tests/baselines/reference/missingDiscriminants2.types |
Baseline for type checking results of the new test |
tests/baselines/reference/missingDiscriminants2.symbols |
Baseline for symbol resolution results of the new test |
tests/baselines/reference/missingDiscriminants2.errors.txt |
Baseline for expected error messages in the new test |
Comments suppressed due to low confidence (1)
src/compiler/checker.ts:1
- [nitpick] The refactored condition combines null check and literal type validation into a single statement, which is more concise. However, consider adding a comment explaining why we return undefined when either condition is met, as this affects discriminated union behavior.
import {
Hey @ahejlsberg, the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: css-tree
|
@ahejlsberg Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
@ahejlsberg Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@ahejlsberg Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Seems like there's a break? |
Yes, that's the same break that caused us to look at the issue in the first place. The problem is that the The fix is to add a export interface WalkOptionsNoVisit {
visit?: never;
enter?: EnterOrLeaveFn | undefined;
leave?: EnterOrLeaveFn | undefined;
reverse?: boolean | undefined;
} |
@typescript-bot run dt |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
Ports microsoft/typescript-go#1757.