Skip to content

Commit 556e0c6

Browse files
authored
[link] Avoid inlining of LinkProps in emitted declarations (#78773)
`tsc` might decide that `LinkProps` should be inlined which would break libraries depending on `next` since that effectively pins the dependency to a patch version. Workaround is explained here: microsoft/TypeScript#37151 (comment) I can't come up with a minimal repro but verified it manually in an internal package. This would've avoided https://github.com/vercel/microfrontends/pull/171 We should probably lint against types that could be interfaces. But really, microsoft/TypeScript#57779 should be fixed. Inlining types from libraries should be configurable. Most dependencies are not pinned to patch versions but majors.
1 parent 323a9c9 commit 556e0c6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/next/src/client/link.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ type InternalLinkProps = {
119119

120120
// `RouteInferType` is a stub here to avoid breaking `typedRoutes` when the type
121121
// isn't generated yet. It will be replaced when the webpack plugin runs.
122+
// WARNING: This should be an interface to prevent TypeScript from inlining it
123+
// in declarations of libraries dependending on Next.js.
124+
// Not trivial to reproduce so only convert to an interface when needed.
122125
// eslint-disable-next-line @typescript-eslint/no-unused-vars
123-
export type LinkProps<RouteInferType = any> = InternalLinkProps
126+
export interface LinkProps<RouteInferType = any> extends InternalLinkProps {}
124127
type LinkPropsRequired = RequiredKeys<LinkProps>
125128
type LinkPropsOptional = OptionalKeys<InternalLinkProps>
126129

0 commit comments

Comments
 (0)