Skip to main content

Oct 2026 · Tutorial · ~8 min read

How to Set Up Next.js with TypeScript from Scratch

By Safdar Ali — frontend engineer, Bengaluru

Start with the official scaffold and turn strictness on before the first feature. Retrofitting strict after a month of any is the hard version. The flags themselves are the subject of strict mode.

Create the app

npx create-next-app@latest my-app --typescript --eslint --app --src-dir=false
cd my-app
npm run dev

I turn the src directory off unless the repo already has one. A smaller root is easier to explain. Tailwind is a separate decision; add it if the design system is utility classes, not because every tutorial includes it.

Keep these compiler options

{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "paths": { "@/*": ["./*"] }
  }
}

noUncheckedIndexedAccess makes items[0] possibly undefined. That is annoying for a day and correct forever. Path aliases stop ../../../components from spreading. Match the alias in the bundler config Next already generated; do not invent a second one.

The first folders

  • app/ for routes, layouts, and metadata.
  • components/ for UI that is not a route.
  • lib/ for functions that do not render.

A longer folder argument is in the structure guide. Do not add a types/ folder of ambient declarations until a real untyped dependency forces it.

If this helped you

I publish free tutorials and write-ups like this in my spare time — no paywall on the guides. If it saved you an afternoon of trial and error, you can support the work:

More guides on safdarali.in — same author, production-focused.

"Talk is cheap. Show me the code."