If five developers are working in the same TypeScript codebase, quality is determined by shared rules, not individual care. If compiler settings, lint rules, folder structure and CI checks aren’t tied to a written standard, everyone brings their own habits; six months later the codebase has split into pieces that don’t resemble each other, and every change breaks something else. Below is an applicable TypeScript standard for a corporate web application: an example tsconfig, ESLint configuration, module boundary rules and CI steps.
The purpose of a code standard
A code standard exists not to end style debates but to catch errors at build time and make the impact of a change predictable. Every rule should answer one of three questions: Does it prevent a runtime error? Does it speed up reading and reviewing code? Does it protect architectural boundaries? Don’t put a rule that touches none of these three into the standard; it produces empty friction in code review.
There are three conditions for the standard to hold up: rules must be applied automatically by tools, the same tools must run with the same version on developer machines and in CI, and exceptions must be visible in the code with their justification. A rule written only on a wiki page isn’t being applied.
Strict tsconfig settings
"strict": true on its own turns on a family of flags; among them are noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, alwaysStrict and useUnknownInCatchVariables (new TypeScript versions may add flags to this family). In a new project this isn’t up for debate. Flags we recommend adding on top that aren’t included in strict:
| Flag | What it catches | Note |
|---|---|---|
noUncheckedIndexedAccess |
The possibility of undefined on array[i] and record access |
The most valuable additional flag; it forces checks into the code |
exactOptionalPropertyTypes |
Explicitly assigning undefined to an optional property |
Strict on API patterns; by team decision |
noImplicitOverride |
Overriding a parent class method without realizing it | Useful in code that uses classes |
noFallthroughCasesInSwitch |
A forgotten break in a switch |
Low cost |
verbatimModuleSyntax |
Type-only imports remaining at runtime | Makes import type mandatory |
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"verbatimModuleSyntax": true,
"isolatedModules": true,
"skipLibCheck": true,
"noEmit": true,
"paths": { "@/*": ["./src/*"] }
},
"include": ["src", "tests"],
"exclude": ["node_modules", "dist"]
}
This example is for a front-end project whose build output is produced by a bundler (Next.js, Vite); with noEmit, TypeScript works only as a type checker. For a back-end service running directly on Node.js, "module": "NodeNext" and "moduleResolution": "NodeNext" are more correct, because they model Node’s ESM/CommonJS resolution rules exactly. paths aliases are only directions for the compiler; they don’t rewrite imports. This is a common reason for services that build cleanly but get a “Cannot find module” error in production. In plain Node.js, the "imports" field in package.json (subpath imports such as #lib/*) is used for the same purpose.
If you turn on all the strict settings at once in an existing project, hundreds of errors appear and the change is usually reverted. The practical way: turn on flags one by one, distribute the errors to module owners and, during the transition, use a commented // @ts-expect-error instead of // @ts-ignore. The latter raises an error itself once the underlying error is fixed; an exception that’s no longer needed thus becomes visible.
Lint and formatting rules
The division of labor is clear: Prettier formats, ESLint checks correctness and architecture rules. Indentation, quote style or line length should never come up in code review. An example configuration in the “flat config” format, the default since ESLint 9, with typescript-eslint rules that use type information:
// eslint.config.mjs
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-config-prettier';
export default [
{ ignores: ['dist/**', '.next/**', 'src/generated/**'] },
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
},
rules: {
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
},
},
{ files: ['**/*.{js,mjs,cjs}'], ...tseslint.configs.disableTypeChecked },
prettier,
];
The reasons behind the rule choices:
no-floating-promisesandno-misused-promises: An un-awaitedPromiseis the most common source of failures where the error is silently swallowed and the record is left half-written. There’s no trace in the log, and data is missing. These rules need type information; that’s why therecommendedTypeCheckedset was chosen.switch-exhaustiveness-check: When a new value is added to a union type (e.g. order status), allswitchblocks that don’t handle it are flagged at build time.no-explicit-any: Data coming from an external source is taken asunknownand narrowed with schema validation.
The disableTypeChecked line turns off rules requiring type information in JavaScript files outside the tsconfig scope, such as eslint.config.mjs; otherwise these files give a “not found in the project service” error. Type-aware linting slows down in large projects. On developer machines, editor integration and a pre-commit hook for changed files are enough; leave the full scan to CI.
Folder structure and module boundaries
As the codebase grows, the real problem isn’t types but the direction of dependencies: a UI component imports the database client directly, one feature reaches into another feature’s internal file. You change one place and an unrelated screen breaks. A feature-oriented structure and explicit boundaries prevent this:
src/
app/ // routes and page composition
features/
order/
index.ts // the feature’s public API
components/
server/ // data access, business rules
schema.ts
stock/
index.ts
...
shared/
ui/ // design system components
lib/ // date, currency, helpers
generated/ // types generated from the API schema (not edited by hand)
The rules: shared can’t import any features module; a feature accesses another feature only through index.ts; server folders can’t be imported from client components. For a first step, ESLint’s built-in no-restricted-imports rule is enough:
{
files: ['src/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': ['error', {
patterns: [{
group: ['@/features/*/*', '!@/features/*/index'],
message: 'Access another feature only through index.ts.',
}],
}],
},
},
This pattern also catches files within a feature itself; that’s why imports within a feature are written with relative paths (./components/...), and the alias is used only for access between features. If the layer matrix is more complex, tools such as eslint-plugin-boundaries or dependency-cruiser let you define dependency rules and verify them in CI. In Next.js web applications, the server-only package is used as an extra lock against server modules leaking into the client bundle; we explained this boundary in detail in the Server and Client Components in the Next.js App Router article.
Sharing and generating API types
Copying types between front end and back end by hand is the shortest route to the contract silently drifting. A field name changes on the back end, the front end compiles, and the error blows up in production. The rule: API types are generated from a single source, not written by hand. The source changes according to the chosen API style:
| API style | Single source | Example generation tool |
|---|---|---|
| REST | OpenAPI document | openapi-typescript |
| GraphQL | Schema + client queries | GraphQL Code Generator |
| Same repository, TypeScript back end | Shared schema package | z.infer from a Zod schema |
npx openapi-typescript ./openapi.yaml -o ./src/generated/api.d.ts
Generated files are kept under src/generated, excluded from linting, regenerated in CI and checked for a zero diff. If someone changes the schema and forgets to update the types, the build breaks. That’s exactly where it should break. But compile-time types aren’t a runtime guarantee: data coming from the network must still be validated at the boundary with a schema library. For forms, the details are in the form validation with a single schema on client and server article, and the choice of API style in the REST or GraphQL comparison.
Type and lint checks in CI
CI is where the standard is actually enforced. On every merge request, these steps should run separately; if one fails, the merge should be blocked:
# package.json scripts
"typecheck": "tsc --noEmit",
"lint": "eslint . --max-warnings=0",
"format:check": "prettier --check .",
"api:generate": "openapi-typescript ./openapi.yaml -o ./src/generated/api.d.ts"
# CI steps
npm ci
npm run api:generate && git diff --exit-code src/generated
npm run typecheck
npm run lint
npm run format:check
--max-warnings=0 is a deliberate choice. A lint step that lets warnings pile up turns within a few months into hundreds of lines of output nobody reads. A warning nobody reads isn’t a warning. If a rule is to stay at warning level, either raise it to an error or turn it off. In monorepos using project references, incremental builds are done with tsc -b instead of tsc --noEmit. The CI/CD pipeline for web projects with GitHub Actions article explains how to put these steps into a pipeline.
A checklist that should go into the standard document:
- Node.js, TypeScript, ESLint and Prettier versions are pinned with a lock file; CI uses the same versions.
strictandnoUncheckedIndexedAccessare on; exceptions use a commented@ts-expect-error.- Type-aware lint rules and
--max-warnings=0are enabled. - Access between features is only through
index.ts; the rule is enforced by lint. - API types are generated, not edited by hand; there’s a diff check in CI.
- Editor settings (
.editorconfig, recommended extensions) are defined in the repository.
When setting up a corporate application’s codebase from scratch or moving a project you’ve inherited to this standard, we can prepare the configuration and the transition plan together within the scope of our custom web application development service. For the full reference of compiler flags, the TypeScript tsconfig reference should be the basis, and for lint rules, the typescript-eslint documentation.
Frequently asked questions
Does it make sense to turn on strict mode all at once in a large existing project?
Usually not. First turn on flags such as noImplicitAny and strictNullChecks one by one and close the errors module by module, then move to strict: true. During the transition, new files can be required to follow strict rules through linting and code review.
Does the tsconfig paths definition also apply at runtime?
No. paths only tells the TypeScript compiler how to resolve modules; it doesn’t rewrite import paths. Tools such as Next.js and Vite read this definition; in a plain Node.js runtime, the imports field in package.json (subpath imports starting with #) or the build tool’s alias support is needed.
How are rule conflicts avoided when Prettier and ESLint are used together?
Formatting is left entirely to Prettier, and ESLint’s formatting rules are turned off with eslint-config-prettier. ESLint deals only with correctness and architecture rules. In CI, prettier –check and eslint run as separate steps.
Should any be banned completely in lint rules?
In application code, the no-explicit-any rule can be kept at error level; for external data, the right way is to use unknown instead of any and narrow it with schema validation. In unavoidable cases such as integrating an old library, an exception is defined with a justified eslint-disable comment and code review approval.