-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
docs(start): clarify verbatimModuleSyntax must be disabled #7806
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
Open
galaxykhh
wants to merge
3
commits into
TanStack:main
Choose a base branch
from
galaxykhh:docs/verbatim-module-syntax-ts6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13
−5
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/router
Length of output: 3773
🏁 Script executed:
Repository: TanStack/router
Length of output: 207
🏁 Script executed:
sed -n '44,52p' docs/start/framework/solid/build-from-scratch.mdRepository: TanStack/router
Length of output: 669
🌐 Web query:
TypeScript verbatimModuleSyntax import type inline type specifiers erased regular imports server-only code💡 Result:
The verbatimModuleSyntax compiler option in TypeScript (introduced in 5.0) mandates that TypeScript performs no automatic elision (removal) of import or export statements [1][2]. By default, TypeScript heuristically determines which imports are types and removes them during compilation [3][4]. When verbatimModuleSyntax is enabled, TypeScript emits import and export statements exactly as written in the source code [2][5]. Key implications include: 1. Explicit Syntax Requirements: Developers must explicitly use the type modifier for type-only imports and exports (e.g., import type { T } from 'mod' or import { type T } from 'mod') [2][4]. If an import is not marked as type, TypeScript assumes it is a value import and will include it in the emitted JavaScript, regardless of whether it is used only as a type in your TypeScript code [2][5]. 2. Handling Inline Type Specifiers: An important nuance is that when you use inline type specifiers—such as import { type A } from 'mod'—verbatimModuleSyntax ensures the type part is erased, but the import statement itself remains in the emitted code [6]. If an import declaration contains no value imports and only inline type specifiers, the resulting JavaScript will still contain an empty import (e.g., import {} from 'mod'), which effectively functions as a side-effect import [6][7]. 3. Server-Only Code and Runtime Safety: Because verbatimModuleSyntax preserves imports that are not explicitly marked as type-only, it prevents unintentional runtime errors where TypeScript might have otherwise elided an import that was actually needed at runtime [2][5]. Conversely, it can cause issues in environments like Next.js where importing from a server-only module into a client component is strictly prohibited [7]. If you import a type from a server-only file using an import declaration that contains side effects (or is not strictly a type-only import), the build tool may incorrectly flag the file as a client-side dependency, leading to errors [7]. 4. Compatibility with Node.js Type Stripping: As of 2026, verbatimModuleSyntax is recommended when working with modern Node.js environments that support native "type stripping" (or erasable syntax), as it enforces the explicit syntax required for Node.js to safely strip types without breaking runtime code execution [8][9][10].
Citations:
"verbatimModuleSyntax": trueerrors after #90907 vercel/next.js#92025🌐 Web query:
site:typescriptlang.org verbatimModuleSyntax inline type specifiers import {} from module emitted code💡 Result:
When the verbatimModuleSyntax compiler option is enabled in TypeScript, the compiler adopts a strict policy regarding imports and exports: it does not transform or elide any import or export statements unless they are explicitly marked with the type modifier [1][2]. For imports and exports containing inline type specifiers, the behavior is as follows: 1. Type-only imports and exports: Any import or export statement that exclusively uses the type modifier (e.g., import type { A } from "a") is erased entirely from the emitted JavaScript code [1]. 2. Mixed imports and exports: If an import or export statement contains both value references and type-only references, the statement is rewritten to remove only the type-only parts [1]. 3. Imports and exports that become empty: If an import or export statement consists entirely of type specifiers (or becomes empty after removing those marked with type), the resulting import or export will be emitted as an empty declaration, such as import {} from "xyz" [1]. This behavior ensures that the emitted code remains consistent with the module format specified by your configuration, preventing TypeScript from implicitly rewriting or eliding code in ways that might conflict with your target module system [1][3].
Citations:
🌐 Web query:
TypeScript verbatimModuleSyntax "import { type" emitted import {} from module💡 Result:
The verbatimModuleSyntax compiler option in TypeScript (introduced in version 5.0) mandates that all import and export statements are emitted exactly as written, with no automatic elision [1][2][3]. Under this setting, TypeScript stops trying to guess whether an import is used as a value or just a type, and instead relies strictly on whether you use the type modifier [2][4]. Regarding the behavior with import { type... } and empty imports: 1. Import Transformation: When you use the type modifier on named imports, TypeScript removes only the type-specific parts during compilation [2]. 2. Emitted Empty Braces: If an import statement consists entirely of type-only named imports, such as import { type T } from "module", TypeScript will rewrite it to import {} from "module" in the emitted JavaScript [5][2]. 3. Why this happens: This behavior is a direct consequence of the verbatim principle—preserving the original module syntax as much as possible [5]. Because the statement was an import declaration, the output retains the import structure even if the named imports are empty, which effectively becomes a side-effect-only import [5][2]. This approach ensures consistency and forces developers to be explicit about their intentions regarding module usage and side effects, rather than having the compiler silently elide code [2][4]. Because it is more predictable and easier to explain, it replaces the older and more complex flags importsNotUsedAsValues and preserveValueImports [6][2].
Citations:
verbatimModuleSyntaxleaves empty curly brackets in the JS output microsoft/TypeScript#62239verbatimModuleSyntax, deprecateimportsNotUsedAsValuesandpreserveValueImportsmicrosoft/TypeScript#52203Clarify that only
import typeis elided. This warning can read as if any type import is safe, butimport { type ... }still emits an import statement. Rephrase it to say the issue is using regular imports for type-only dependencies from server-only modules.🤖 Prompt for AI Agents