๐—ง๐˜†๐—ฝ๐—ฒ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—•๐—ฒ๐˜€๐˜ ๐—ฃ๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ฐ๐—ฒ๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜…๐˜.๐—ท๐˜€ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ

Many Next.js projects claim to use TypeScript but do not follow it. They use strict mode in the config but rely on type assertions and implicit any. This leads to crashes at runtime.

True TypeScript requires the right configuration and patterns.

Update your tsconfig.json with these settings:

โ€ข noUncheckedIndexedAccess: This makes arr[0] return T | undefined. It stops crashes when arrays are empty. โ€ข noImplicitOverride: This forces you to use the override keyword in subclasses. โ€ข exactOptionalPropertyTypes: This ensures { x?: string } stays distinct from { x: string | undefined }. โ€ข forceConsistentCasingInFileNames: This prevents import bugs on Linux systems. โ€ข noPropertyAccessFromIndexSignature: This forces you to use bracket notation for indexed types.

Stop using type assertions like "value as Type". This tells the compiler to stop checking your code. Instead, use type guards or Zod.

Follow these patterns to keep your code safe:

  1. Server Actions Do not use "formData.get() as string". Parse and validate your FormData with Zod at the top of every action. This turns unknown input into typed data.

  2. API Fetches The response.json() method returns any. Use a typed wrapper with Zod to parse the response. This ensures the data matches your expected shape.

  3. Environment Variables Do not use "process.env.KEY as string". Create a utility to validate your variables at startup. If a key is missing, your app should throw an error immediately.

  4. Component Props Avoid using many optional props that depend on each other. Use discriminated unions instead. This makes invalid states impossible to represent in your code.

Summary of changes:

Source: https://dev.to/thekitbase/typescript-best-practices-for-nextjs-projects-in-2026-40pi