Skip to the solution
MediumFrontend11 min read

How do you fix JSX and type-only import errors under verbatimModuleSyntax?

532 views

The problem

Question presented to candidate: "We enabled verbatimModuleSyntax in our React app and now App.tsx and our component barrel files fail to compile. Walk me through the errors you expect, how you fix each one, and how you would fix a few hundred files without doing it by hand."

What a strong answer should cover:

  • Props types, FC, ReactNode and other types need import type or an inline type modifier (TS1484); components used in JSX are values and must stay plain imports
  • Barrel files that re-export props types need export type { ... } (TS1205)
  • Over-fixing breaks too: a component imported with import type and used in JSX is TS1361, and import type React, { useState } is TS1363
  • The JSX runtime matters: with jsx: "react-jsx" the compiler adds import { jsx as _jsx } from "react/jsx-runtime" and an old import React becomes an unused import that is still emitted; with classic jsx: "react", React must be a value import
  • Files that emit CommonJS fail with TS1286; the fix is ESM output, not more type keywords
  • Bulk fixes: the TypeScript quick fix "Fix all with type-only imports", typescript-eslint consistent-type-imports with --fix, and type-only auto-imports in the editor

Clarifying questions expected:

  • Which JSX setting does the project use (react-jsx or classic react)?
  • Does the build emit ESM or CommonJS (module setting and package.json "type")?

Code / implementation expected: Yes β€” a broken component file and its fixed version, plus a barrel file fix.

  • verbatimModuleSyntax
  • jsx

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

11 min read Β· 12 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

TypeScriptFixing a component file: inline vs separate type imports

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 42 of 81 in TypeScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

When should you use `moduleResolution: "bundler"` versus `"nodenext"`?

Continue