fix(checker): emit TS2845 for exported enum member truthiness checks (#63565) - #64254
Open
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
Open
fix(checker): emit TS2845 for exported enum member truthiness checks (#63565)#64254Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
Conversation
Copilot started reviewing on behalf of
Vaibhav Srivastava (vaibhavsrv)
September 13, 2026 07:02
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Merged enum namespaces can trigger a checker panic, and the new compiler-test baselines are missing.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes TS2845 detection for exported enum-member truthiness checks.
Changes:
- Resolves exported and merged enum symbols.
- Evaluates constant enum-member values.
- Adds a regression test.
File summaries
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Extends enum truthiness diagnostics. |
tsc/testdata/tests/cases/conformance/controlFlow/exportedEnumTruthinessTS2845.ts |
Adds the exported-enum scenario. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
Comment on lines
+3880
to
+3884
| propSym := c.getSymbolAtLocation(location.AsPropertyAccessExpression().Name(), false) | ||
| if propSym != nil && len(propSym.Declarations) > 0 { | ||
| enumVal := c.getEnumMemberValue(propSym.Declarations[0]) | ||
| val = enumVal.Value | ||
| } |
| declare const type: AdapterOutputType; | ||
|
|
||
| const kind = | ||
| type === AdapterOutputType.APP_PAGE || AdapterOutputType.PAGES |
Vaibhav Srivastava (vaibhavsrv)
force-pushed
the
fix/exported-enum-ts2845
branch
from
September 13, 2026 07:24
5eb992b to
675911d
Compare
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.
Fixes #63565
Summary of Changes
This PR fixes a diagnostic bug where truthiness expressions evaluating constant
enummembers (e.g.,AdapterOutputType.PAGES) failed to emitTS2845: This condition will always return 'true'when theenumdeclaration was marked withexport.Root Cause
In
tsc/internal/checker/checker.go,checkTestingKnownTruthyTypepreviously checkedt.flags & TypeFlagsEnumLiteral != 0. While unexported enum members retainTypeFlagsEnumLiteral, exported enum members are widened toTypeFlagsEnum, causing the truthiness check to be skipped.Fix
checkTestingKnownTruthyTypeto inspect property access expressions onEnumsymbols regardless ofexportwidening.c.getEnumMemberValueto determine truthiness whenTypeFlagsEnumLiteralis absent.TS2845based onevaluator.IsTruthy(val).Verification
enum: emitsTS2845.export enum: now correctly emitsTS2845.