Skip to content

ref(types): narrow type in Promise.catch from any to unknown#114849

Merged
TkDodo merged 7 commits into
masterfrom
tkdodo/ref/promise-catch-unknown
May 6, 2026
Merged

ref(types): narrow type in Promise.catch from any to unknown#114849
TkDodo merged 7 commits into
masterfrom
tkdodo/ref/promise-catch-unknown

Conversation

@TkDodo
Copy link
Copy Markdown
Collaborator

@TkDodo TkDodo commented May 5, 2026

Adds a global type declaration that overrides Promise.catch and .then rejection callbacks to receive unknown instead of any. This forces explicit type narrowing at every catch site, preventing silent property access on untyped error objects.

Type Declaration

A new static/app/types/promise.d.ts re-declares the Promise interface so that onrejected receives unknown. This is the same approach TypeScript uses for catch(e) in try/catch blocks since useUnknownInCatchVariables, but applied to Promise chains which TypeScript doesn't cover natively.

Call Site Fixes

Each .catch / .then(_, onrejected) handler is updated to narrow the error before accessing properties — typically via instanceof RequestError, explicit (err: Error) annotations, or (err: any) where the handler's shape is too dynamic to narrow cleanly right now.

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 5, 2026
@TkDodo
Copy link
Copy Markdown
Collaborator Author

TkDodo commented May 5, 2026

bugbot run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

📊 Type Coverage Diff

Metric Before After Delta
Coverage 93.40% 93.44% 🟢 +0.04%
Typed 134,863 134,935 🟢 +72
Untyped 9,533 9,473 🟢 -60
🔍 6 new type safety issues introduced

Type assertions (as) (6 new)

File Line Detail
static/app/actionCreators/projects.tsx 146 as stringerr.responseJSON.detail as string
static/app/components/selectMembers/index.tsx 144 as Errorerr as Error
static/app/views/performance/transactionSummary/transactionThresholdButton.tsx 87 as stringerrorMessage as string
static/app/views/performance/transactionSummary/transactionThresholdModal.tsx 101 as stringerrorMessage as string
static/app/views/performance/transactionSummary/transactionThresholdModal.tsx 147 as stringerrorMessage as string
static/app/views/settings/project/projectOwnership/ownerInput.tsx 92 as InputErrorcaught.responseJSON as InputError

This is informational only and does not block the PR.

Comment thread static/app/views/discover/table/index.tsx Outdated
Comment thread static/app/actionCreators/performance.tsx Outdated
@TkDodo TkDodo marked this pull request as ready for review May 5, 2026 13:13
@TkDodo TkDodo requested review from a team as code owners May 5, 2026 13:13
Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Onion 'sickos' guy smiling 'yes... ha ha ha ... yes' at a window meme template with 'TYPES' on his shirt

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9e84ef3. Configure here.

Comment thread static/app/types/promise.d.ts
Comment thread static/app/views/settings/project/projectOwnership/ownerInput.tsx
TkDodo and others added 2 commits May 6, 2026 10:27
The TFul generic parameter was missing the = T default that the
standard TypeScript Promise interface provides. Without it, calling
.then(null, rejectionHandler) infers TFul as unknown instead of T,
collapsing the result to Promise<unknown>.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TkDodo TkDodo enabled auto-merge (squash) May 6, 2026 08:28
@TkDodo TkDodo merged commit 87a02ec into master May 6, 2026
72 of 73 checks passed
@TkDodo TkDodo deleted the tkdodo/ref/promise-catch-unknown branch May 6, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants