API Reference

Last updated:

API Reference

findTsConfig() / findTsConfigSync()

Find a tsconfig.json file by searching upward (falling back to jsconfig.json). findTsConfig is asynchronous; findTsConfigSync is the synchronous variant. Throws when no config file is found.

Signature:

function findTsConfig(cwd?: URL | string, options?: FindTsConfigOptions): Promise<TsConfigResult>;

function findTsConfigSync(cwd?: URL | string, options?: FindTsConfigOptions): TsConfigResult;

Options (FindTsConfigOptions, extends ReadTsConfigOptions):

  • configFileName - Name of the file to search for. Defaults to "tsconfig.json". Supplying a custom name disables the jsconfig.json fallback.
  • cache - boolean | Map<string, TsConfigResult>. true uses a process-wide cache; pass a Map for a caller-owned cache. Keys embed the file mtime, so on-disk edits invalidate cached entries automatically.
  • tscCompatible, typescriptVersion - forwarded to readTsConfig.

Only the upward file search is async. Parsing (including the full extends chain) is synchronous.

readTsConfig()

Read and parse a tsconfig.json file. This function is synchronous — it returns the resolved config object directly (no await).

Signature:

function readTsConfig(
    tsconfigPath: string,
    options?: {
        tscCompatible?: "5.4" | "5.5" | "5.6" | "5.7" | "5.8" | "5.9" | "6.0" | true;
        typescriptVersion?: "auto" | false | string;
    },
): TsConfigJsonResolved;

Options:

  • tscCompatible - Synthesize the derived defaults TypeScript would imply from other options for the given version (e.g. module: nodenextmoduleResolution: nodenext). true targets the latest supported version. Default undefined.
  • typescriptVersion - Apply the unconditional compiler-option defaults of a TypeScript version. "auto" detects the installed version (including Yarn PnP); a string pins an explicit version; false (default) applies none. Can be combined with tscCompatible.

writeTsConfig() / writeTsConfigSync()

Write the provided TypeScript configuration object to a tsconfig.json file. writeTsConfig is asynchronous; writeTsConfigSync is the synchronous variant.

Signature:

function writeTsConfig(tsConfig: TsConfigJson, options?: WriteJsonOptions & { cwd?: URL | string }): Promise<void>;

function writeTsConfigSync(tsConfig: TsConfigJson, options?: WriteJsonOptions & { cwd?: URL | string }): void;

Options:

  • cwd - Directory to write tsconfig.json (plus any @visulima/fs WriteJsonOptions).

TsConfig Type

interface TsConfig {
    extends?: string | string[];
    compilerOptions?: CompilerOptions;
    include?: string[];
    exclude?: string[];
    files?: string[];
    references?: ProjectReference[];
    // ... all TypeScript config options
}
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues