🎨 Narrow AbortAddon controller() return type to AbortController#316
Merged
Merged
Conversation
The controller() resolver always returns the request's AbortController at runtime (created in beforeRequest), so type the first element of the returned pair as AbortController instead of any. Consumers keep full type safety on the returned controller (.abort(), .signal, …) instead of an unchecked any. Adds a type-level test under test/types/. Type-only change, no runtime impact.
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.
What
.controller()is typed as() => [any, this], so the first element of the returned pair isany. At runtime it is always the request'sAbortController(created inbeforeRequest), so this narrows the type to[AbortController, this].Why
With
any, callers lose all type safety on the returned controller — the documentedc.abort()usage isn't checked, and typos slip through silently:This is a type-only change — runtime behaviour is unchanged. (Same spirit as #314.)
Tests
Adds
test/types/abort-controller.ts, which asserts the narrowed return type and includes a@ts-expect-errorthat fails if the type ever regresses back toany.npm run test:typesandnpm run test:nodeboth pass locally.