liveBook · Manning

traceResolution

As explained in Essential TypeScript 5, Third Edition

traceResolution is a TypeScript compiler option that reports the locations and settings involved in module and declaration-file resolution.

traceResolution is a TypeScript compiler option for diagnosing module and declaration-file resolution. It reports the locations and settings the compiler checks while locating dependencies. The output can be verbose, especially in complex projects, but a successful-resolution message confirms which file the compiler will use. section 15.3.3 section 15.3.5

Trace a package declaration

Run the compiler from the project folder: tsc --traceResolution For the debug package, the output can include: ======== Module name 'debug' was successfully resolved to 'C:/usingjs/types/debug.d.cts'. ======== For Chalk, it can identify the package declaration and package version: ======== Module name 'chalk' was successfully resolved to 'C:/usingjs/node_modules/chalk/index.d.ts' with Package ID 'chalk/index.d.ts@4.1.2'. ======== Use the trace when a package appears not to have usable types or when the compiler resolves an unexpected file. section 15.3.3 section 15.3.5

Listing 15.26 Running the compiler
tsc --traceResolution

Shows the command-line form used to request resolution diagnostics. section 15.3.3

Listing 15.23 Configuring the compiler in the tsconfig.json file in the usingjs folder
{
    "compilerOptions": {
        "target": "ES2022",
        "outDir": "./dist",
        "rootDir": "./src",
        "module": "Node16",
        "allowJs": true,
        "checkJs": true,
        "baseUrl": ".",
        "paths": {
            "*": ["types/*.d.cts", "types/*.d.mts", "types/*.d.ts"]
        },
    }
}

Shows a project configuration whose paths settings help the compiler locate custom declaration files. section 15.3.3

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Reports checked locations, configuration effects, and successful targets, but leaves the verbose resolution process for the reader to inspect.
Examples
Uses debug and Chalk packages, custom declaration files, compiler commands, and successful-resolution trace messages.
What it assumes
Assumes familiarity with TypeScript compilation, tsconfig.json, packages, imports, and declaration files.
What you can do after
Diagnose dependency resolution by running tsc --traceResolution and identifying the declaration or module file selected.
How it connects
Connects module resolution with declaration files, package.json settings, paths, and type declarations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.