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 devI 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:
- Buy me a coffee at buymeacoffee.com/safdarali
- Subscribe to my YouTube channel — it's free; 70+ React & Next.js tutorials
Related reading
More guides on safdarali.in — same author, production-focused.
- Tutorial
Claude API + Next.js — Building AI Features in Your Web App
Claude API Next.js tutorial — build AI features with server actions, streaming, and error handling in a production app.
Aug 2026Read article →
- Tutorial
Prisma + PostgreSQL + Next.js — Full Stack Setup Guide
Prisma Next.js tutorial — PostgreSQL setup, schema design, server-side queries, and production deploy checklist.
Jul 2026Read article →