Repository navigation
Conversation
Remove another 158 `as any` casts (62 in packages/next/src, 96 in
tests). Some changes here are runtime code, but each one behaves
identically for every input, including null/primitives, Proxies,
setters, frozen objects, `this` binding and evaluation order. `in`
checks, new null guards, `?.` and coercions are deliberately not used,
because they behave differently in edge cases.
Tests:
- Read `isNextDev`/`isNextDeploy`/`isNextStart` from `e2e-utils`
instead of `(global as any)`. `nextTestSetup()` returns getters for the
same exports. The global is `true | undefined` while the export is a
boolean; every use is in a boolean context (`if`, `!`, ternaries,
defaulted params), so this is equivalent. `next-test-utils` keeps the
global read because it is also used without `e2e-utils`, and importing
that would run its side effects.
packages/next:
- `Object.assign(target, { k: v })` instead of casting and assigning:
same [[Set]], same order, same throw-on-failure in strict mode (babel
parse errors, prerender-interrupted error, bubbled base-server error,
`_ogBody`, resolved IO promise, redirect error `handled`, telemetry
response, `NEXT_BUILTIN_DOCUMENT`, sandbox router context).
- Small typed helpers with identical calls: `inLayerGroup`,
`excludesFalse` and a type-predicate arrow for `.filter(Boolean)`.
- Typed `.call`/`.apply` for the process and crypto patches in
node-environment-extensions; `this` and `arguments` pass through
unchanged.
- Delete the unused `future` plumbing from the webpack config context;
nothing reads `ctx.future`.
- Type-only leftovers: overloads for `resolveAsArrayOrUndefined`, an
internal `__appRouter` marker on `CompletePrivateRouteInfo`, a nullable
dev-only WeakMap in `use-action-queue`, and dropping casts in
`headers.test.ts`/`request-cookies.test.ts` now that the sealed types
declare those methods.
Contributor
Failing test suitesCommit: 6dea1a6 | About building and testing Next.js
Expand output● app-dir static/dynamic handling › should cache correctly handle JSON body |
This branch has not been deployed
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.
Stacked on #100418 (type-only changes). Review that one first; this PR's diff is only the second commit.
Summary
Removes another ~156
as anycasts: 62 inpackages/next/src(153 → 91) and ~94 in tests. Unlike the previous PR, some of these change runtime code. Each one still behaves identically for every input, includingnull/primitives, Proxies, setters, frozen objects,thisbinding and evaluation order. Rewrites that only differ in edge cases (inchecks, new null guards,?., coercions) are deliberately left out.Tests
isNextDev/isNextDeploy/isNextStartfrome2e-utilsinstead of(global as any).nextTestSetup()returns getters for the same exports.true | undefinedand the export is a boolean. Every use is in a boolean context (if,!, ternaries, defaulted params), so the two are interchangeable.next-test-utilskeeps its global read: it is also loaded withoute2e-utils, and importing that module would run its side effects.packages/next
Object.assign(target, { k: v })instead of a cast plus property assignment, with the same[[Set]], the same order and the same strict-mode throw behaviour. This covers:_ogBodyhandledflagNEXT_BUILTIN_DOCUMENTinLayerGroup,excludesFalse, and a type-predicate arrow for.filter(Boolean)..call/.applyfor theprocessand crypto patches innode-environment-extensions;thisandargumentspass through unchanged.futureplumbing from the webpack config context; nothing readsctx.future.resolveAsArrayOrUndefined__appRoutermarker onCompletePrivateRouteInfoWeakMapinuse-action-queueheaders.test.ts/request-cookies.test.ts, now that the sealed types declare those methodsVerification
tsc --noEmitforpackages/nextand for the root project (tests). The root check's only errors arenext/distresolution misses in untouched tests, because the local worktree has no build.test/unitincremental-cache / sandbox / webpack-config suites. All pass except the 2fast-set-immediate.external.test.tstests that also fail oncanarylocally.isNextXswap (e.g.app-static,middleware-general,prerender), which need a full build; relying on CI.