fix(next): accept interface-typed next config in withPrewire - #1
Merged
Conversation
`NextConfig` is an interface, and interfaces get no implicit index signature, so the `C extends Record<string, unknown>` constraint rejected `withPrewire(nextConfig)` for every app that types its config — which is every app the docs tell you to write. The constraint is only there to stop primitives, so `C extends object` covers it without the structural requirement. Regression test uses an interface-typed config, since an object literal passes under either constraint. Also documents resolving `#prewire` when shared packages are consumed as source (Next transpilePackages and friends): `#…` specifiers are package-local by spec, so the mapping must come from the app's tsconfig paths, and the emitted prewire.paths.gen.json cannot be extends-merged by an app that declares paths of its own — TypeScript replaces `paths` across `extends` rather than merging.
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.
Problem
withPrewire<C extends Record<string, unknown>>rejectsNextConfig:NextConfigis an interface, and interfaces get no implicit index signature.The README's own snippet (
withPrewire({ reactStrictMode: true })) passes onlybecause an object literal is inferred as an anonymous type — the moment an app
does the normal thing:
it fails to typecheck. Hit while adopting prewire in a real Next 16 monorepo.
Fix
C extends object. The constraint only exists to exclude primitives; thestructural
Recordrequirement buys nothing and excludes every interface.The regression test deliberately declares an interface-typed config — an object
literal passes under either constraint, so it would not have caught this.
Also
README gets a section on resolving
#prewirewhen shared packages are consumedas source (
transpilePackagesand friends), which the current docs do notcover. Two findings from the migration:
#…subpath imports are package-local by spec, so a#prewireinsidepackages/kit/srccannot resolve to the importing app's root viapackage.jsonimports. The app's tsconfigpathsis sufficient andTurbopack honours it for transpiled workspace sources — no bundler alias
needed (verified on Next 16.1.4,
next build, 3 apps).tsconfigPaths: trueemitsprewire.paths.gen.jsonfor the app tsconfig toextends, but TypeScript replacescompilerOptions.pathsacrossextendsinstead of merging. Any app with its own@/*alias silently losesthe generated mapping. Documented the
tsconfigPaths: false+ inline entryroute.
Worth considering separately: codegen already patches
package.jsonimportsin place whenconditionsis set; doing the same for auser-named tsconfig would close the gap, but tsconfig is frequently JSONC
and a comment-preserving rewrite is not free. Docs felt like the honest
fix for now.
Verification
bun run lint,bun run build,bun run test,prettier --check .— allgreen.
@prewire/nexttests 4 → 5.