Skip to content

fix(checker): emit TS2845 for exported enum member truthiness checks (#63565) - #64254

Open
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
microsoft:mainfrom
vaibhavsrv:fix/exported-enum-ts2845
Open

fix(checker): emit TS2845 for exported enum member truthiness checks (#63565)#64254
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
microsoft:mainfrom
vaibhavsrv:fix/exported-enum-ts2845

Conversation

@vaibhavsrv

Copy link
Copy Markdown

Fixes #63565

Summary of Changes

This PR fixes a diagnostic bug where truthiness expressions evaluating constant enum members (e.g., AdapterOutputType.PAGES) failed to emit TS2845: This condition will always return 'true' when the enum declaration was marked with export.

Root Cause

In tsc/internal/checker/checker.go, checkTestingKnownTruthyType previously checked t.flags & TypeFlagsEnumLiteral != 0. While unexported enum members retain TypeFlagsEnumLiteral, exported enum members are widened to TypeFlagsEnum, causing the truthiness check to be skipped.

Fix

  1. Refined checkTestingKnownTruthyType to inspect property access expressions on Enum symbols regardless of export widening.
  2. Unaliased and merged symbols for enum entity lookups.
  3. Evaluated the enum member's constant initializer via c.getEnumMemberValue to determine truthiness when TypeFlagsEnumLiteral is absent.
  4. Correctly emitted diagnostic TS2845 based on evaluator.IsTruthy(val).

Verification

  • Verified against unexported enum: emits TS2845.
  • Verified against exported export enum: now correctly emits TS2845.
  • All internal checker unit tests pass cleanly.

Copilot AI balanced review requested due to automatic review settings September 13, 2026 07:01
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 13, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Sep 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 thread tsc/internal/checker/checker.go Outdated
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

export modifier on enum disables This condition will always return * ts2845

2 participants