Skip to content

Ensure declaration reference published paths #64476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Apr 14, 2024

We currently emit declaration for files that reference unknown modules e.g. export { default as GlobalError } from 'VAR_MODULE_GLOBAL_ERROR'; in next/dist/build/templates/app-page.d.ts.

Since the referenced modules are declarated in compiled.d.ts which we do publish, I see no reason to not also let next/dist/build/templates/app-page.d.ts reference the appropriate ambient declaration file (compiled.d.ts).

The alternative is marking the whole module as @internal but checking if every export truly never flows into a public module takes way more time.

This also unblocks the TypeScript 5.4 upgrade in #64043. TS 5.4 would emit a declaration referencing the appropriate ambient declaration but since compiled.d.ts is not part of the program but misc.d.ts is, the declaration would reference misc.d.ts(/// <reference path="../../../types/misc.d.ts") which is not published and would cause TypeScript compilation to fail.

Closes NEXT-3104

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. type: next labels Apr 14, 2024
Copy link
Member Author

Choose a reason for hiding this comment

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

All of the removed modules are already declared in compiled.d.ts

@eps1lon
Copy link
Member Author

eps1lon commented Apr 14, 2024

This doesn't work. We have some modules that have more specific types internally because we have the types available as a dependency (e.g. Webpack). When published, the Webpack dependency is stripped and replaced with a looser definition based on what we assume is actually emitted. I don't think TypeScript supports this pattern outside of @internal annotations.

compiled.d.ts isn't even referenced by any emitted declaration at the moment while the non-published misc.d.ts is.

Need to dig deeper why some declarations are emitted in the first place.

@eps1lon eps1lon closed this Apr 14, 2024
@eps1lon eps1lon deleted the sebbie/reference-published branch April 14, 2024 21:21
@eps1lon eps1lon restored the sebbie/reference-published branch April 14, 2024 21:21
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants