QA Interview Hub · Knowledge base · Quizzes · Українська

TypeScript › Modules and tsconfig

tsconfig for a test project

tsconfig.json is read in full by tsc and the editor, while Playwright takes only a few options from it and does not check types. So a test with a type error still runs, and types in CI are checked by a separate npx tsc --noEmit step. Useful options are strict, noUncheckedIndexedAccess and verbatimModuleSyntax, and include must cover every test directory, otherwise types there go unchecked.

TypeScript · Modules and config

A test with a type error runs and passes. So what is tsconfig for in a Playwright project?

The repository has a thirty-line tsconfig.json, but a test with an obvious type error (amount: "100" instead of a number) runs calmly and Playwright says nothing. Meanwhile the IDE underlines the same line in red. So the config works, but not where people expect. This lesson looks at what Playwright takes from it, what only tsc and the editor use, and which set of options is reasonable for a test project in 2026.

How it works and why. tsconfig.json is read by different consumers and each takes its own. The tsc compiler and the editor (language service) use it fully: they check types by all options. Playwright transpiles TS without type checking and takes only a small part of the whole config: allowJs, baseUrl, paths, JSX settings, useDefineForClassFields, references and extends. It needs target only to determine useDefineForClassFields. The tsconfig is taken nearest to each file, so a separate tsconfig.json in the tests directory applies only to them.

Who reads what from tsconfig

Playwright

Only a small part

paths, baseUrl, allowJs, JSX, extends, references. It does not check types: strict does not affect the run.

tsc / IDE

All options

strict, module, include, types, noEmit and the rest. This is where type errors appear.

Figure 1. Two consumers, not a choice: both need the config, and CI must run tsc separately.

Example: a minimal config for a test project.

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "types": ["node"],
    "paths": { "@pages/*": ["./src/pages/*"], "@api/*": ["./src/api/*"] }
  },
  "include": ["tests", "src", "playwright.config.ts"]
}

What the key options mean:

  • strict: a group of checks (strictNullChecks, noImplicitAny, useUnknownInCatchVariables and others). Since TypeScript 6.0 it is on by default, but it is better to set it explicitly: the intent is visible and the config reads the same in older versions.
  • noUncheckedIndexedAccess: arr[0] and an index signature entry have type T | undefined, so an «empty list» does not pass unnoticed.
  • module: NodeNext: module and import resolution rules follow Node (moduleResolution is taken from it). For code a bundler builds you choose module: ESNext with moduleResolution: Bundler.
  • verbatimModuleSyntax: every import stays as written, so types are imported with import type; this also makes the code compatible with transpilers that cannot see types.
  • noEmit: type checking only, no JS is produced, running stays with Playwright.
  • types: which global type packages to include. Since TypeScript 6.0 the default is empty, so process without "types": ["node"] gives TS2591.
  • paths: aliases instead of ../../../pages. Playwright supports them and baseUrl is not needed for this: since TypeScript 6.0 it is deprecated (TS5101), and paths are written relative to the config file.
  • skipLibCheck: do not check .d.ts files. It speeds things up but also hides errors in your own .d.ts files.

What breaks and how to read it. A typical situation: module: NodeNext and verbatimModuleSyntax were enabled but package.json has no "type": "module". The file is then treated as CommonJS and the compiler complains about every import; the second error appears only after switching to "type": "module" (messages shortened):

src/a.ts: TS1295: ECMAScript imports and exports cannot be
  written in a CommonJS file under 'verbatimModuleSyntax'.
(after "type": "module")
src/a.ts: TS2835: Relative import paths need explicit file
  extensions in ECMAScript imports when '--moduleResolution'
  is 'node16' or 'nodenext'. Did you mean './pages/login.js'?
(messages shortened)

The first line reads: ESM syntax in a CommonJS file. It is cured by either "type": "module" or changing module. The second line: in an ESM package under NodeNext relative imports need an extension, and it is .js even though the file on disk is .ts, because the compiler looks at the path that will be in the output JS:

import { LoginPage } from '@pages/login.js';   // through paths
import { helper } from './helper.js';            // relative path: .js even though the file is .ts
import type { Account } from './models.js';     // a type: verbatimModuleSyntax requires type

Limits and alternatives. include matters only to tsc and the editor: a file missing from the list is not checked although Playwright will run it. That is how a «new» tests folder easily ends up without type checking. For different parts of a repository a base tsconfig.base.json is made along with separate configs that inherit it through extends:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": { "types": ["node", "mocha"] },
  "include": ["api-tests"]
}

Project references (composite and references) solve a different task, building dependent projects in the right order, and a test repository rarely needs them. When the code is run not by Playwright but by Node 24 itself in type-stripping mode (node test.ts), it ignores tsconfig: paths do not apply there, subpath imports (#...) in package.json are needed, and the erasableSyntaxOnly option in tsc forbids enum and parameter properties, which this mode does not support.

Common mistakes.

  • Assuming strict in tsconfig will stop a Playwright run: only tsc checks types, and it is missing in CI.
  • include without the new tests folder: files run but their types are not checked.
  • Forgetting "types": ["node"] with TypeScript 6.0: process and Buffer are not found (TS2591).
  • Copying baseUrl, moduleResolution: node10 or esModuleInterop: false from old examples: in 6.0 these are deprecated options (TS5101, TS5107).
  • Importing your own files without an extension in an ESM package under NodeNext: TS2835.

Check yourself

The project has no tsc step in CI and a test has await page.goto(123). Why can the run be green and what must be added?

Answer

Playwright does not check types: it transpiles the file and runs it. Only the IDE or tsc will see the type error. A separate npx tsc --noEmit step must be added (and noEmit in the config prevents creating extra files).

Which tsconfig fields does Playwright need to resolve the import @pages/login, and which do not affect the run: paths, strict, include?

Answer

Only paths is needed: Playwright reads it for aliases. strict and include concern only type checking in tsc and the editor and do not affect running tests.

In an interview. Junior: In tsconfig I enable strict, noEmit and paths for short imports. Playwright does not check types, so I run tsc --noEmit separately in CI. Middle/Senior: I know who reads what: Playwright takes paths, extends and a few other options, while strict, include, types matter to tsc and the IDE. I add noUncheckedIndexedAccess, verbatimModuleSyntax, an explicit "types": ["node"] (empty by default since TypeScript 6.0) and make sure include covers all test folders.

More articles in this chapter