Properties


base_config

Returns the base TSConfig that this config inherits from.

Gets the base configuration file that this TSConfig extends. The base configuration is used for inheriting settings like paths, baseUrl,and other compiler options.

Returns: TSConfig | None: The parent TSConfig object if this config extends another config file, None otherwise.

def base_config(self) -> "TSConfig | None":
    ...

base_url

Returns the base URL defined in the TypeScript configuration.

This property retrieves the baseUrl from the project’s TypeScript configuration file. The baseUrl is used for resolving non-relative module names.

Returns: str | None: The base URL if defined in the config file or inherited from a base config, None if not specified.

def base_url(self) -> str | None:
    ...

out_dir

Returns the outDir defined in the TypeScript configuration.

The outDir specifies the output directory for all emitted files. When specified, .js (as well as .d.ts, .js.map, etc.) files will be emitted into this directory. The directory structure of the source files is preserved.

Returns: str | None: The output directory path if specified in the config file or inherited from a base config, None if not specified.

def out_dir(self) -> str | None:
    ...

path_import_aliases

Returns a formatted version of the paths property from a TypeScript configuration file.

Processes the paths dictionary by formatting path patterns and their corresponding target paths. All wildcards (*), trailing slashes, and double slashes are removed from both the path patterns and their target paths. Target paths are also converted from relative to absolute paths.

Returns: dict[str, list[str]]: A dictionary where keys are formatted path patterns and values are lists of formatted absolute target paths.

def path_import_aliases(self) -> dict[str, list[str]]:
    ...

paths

Returns all custom module path mappings defined in the tsconfig file.

Retrieves path mappings from both the current tsconfig file and any inherited base config file, translating all relative paths to absolute paths.

Returns: dict[str, list[str]]: A dictionary mapping path patterns to lists of absolute path destinations. Each key is a path pattern (e.g., ’@/*’) and each value is a list of corresponding absolute path destinations.

def paths(self) -> dict[str, list[str]]:
    ...

reference_import_aliases

Returns a formatted version of the references property from a TypeScript configuration file.

Processes the references dictionary by formatting reference paths and their corresponding target paths. For each reference, retrieves its tsconfig file and path mappings. Also includes any path mappings inherited from base configs.

Returns: dict[str, list[str]]: A dictionary where keys are formatted reference paths (e.g. ‘module/dist’) and values are lists of absolute target paths derived from the referenced tsconfig’s rootDirs and outDir settings.

def reference_import_aliases(self) -> dict[str, list[str]]:
    ...

references

Returns a list of directories that this TypeScript configuration file depends on.

The references are defined in the ‘references’ field of the tsconfig.json file. These directories are used to resolve import conflicts and narrow the search space for import resolution.

Returns: list[Directory | File | TSConfig]: A list of Directory, File, or TSConfig objects representing the dependent directories.

def references(self) -> list[Directory | File]:
    ...

root_dir

Returns the rootDir defined in the TypeScript configuration.

The rootDir specifies the root directory of input files. This is used to control the output directory structure with outDir. When TypeScript compiles files, it maintains the directory structure of the source files relative to rootDir when generating output.

Returns: str | None: The root directory path if specified in the config file or inherited from a base config, None if not specified.

def root_dir(self) -> str | None:
    ...

root_dirs

Returns the rootDirs defined in the TypeScript configuration.

The rootDirs allows a list of root directories to be specified that are merged and treated as one virtual directory. This can be used when your project structure doesn’t match your runtime expectations. For example, when you have both generated and hand-written source files that need to appear to be in the same directory at runtime.

Returns: list[str]: A list of root directory paths specified in the config file or inherited from a base config. Returns an empty list if not specified.

def root_dirs(self) -> list[str]:
    ...

Methods


resolve_base_url

Resolves an import path with the base url.

If a base url is not defined, try to resolve it with its base config.

def resolve_base_url(self, import_path: str) -> str:
    ...

translate_absolute_path

Translates an absolute path to an import path using the tsconfig paths.

Takes an absolute path and translates it to an import path using the configured paths in the tsconfig file.

For example, converts a/b/c/my/pkg/src to @abc/my/pkg/src or however it’s defined in the tsconfig.

Args: import_path (str): The absolute path to translate.

Returns: str: The translated import path.

def translate_absolute_path(self, absolute_path: str) -> str:
    ...

translate_import_path

Translates an import path to an absolute path using the tsconfig paths.

Takes an import path and translates it to an absolute path using the configured paths in the tsconfig file. If the import path matches a path alias, it will be resolved according to the tsconfig paths mapping.

For example, converts @abc/my/pkg/src to a/b/c/my/pkg/src or however it’s defined in the tsconfig.

Args: import_path (str): The import path to translate.

Returns: str: The translated absolute path. If no matching path alias is found, returns the original import path unchanged.

def translate_import_path(self, import_path: str) -> str:
    ...

Was this page helpful?