TsconfigAPI Reference
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 thejsconfig.jsonfallback.cache-boolean | Map<string, TsConfigResult>.trueuses a process-wide cache; pass aMapfor a caller-owned cache. Keys embed the file mtime, so on-disk edits invalidate cached entries automatically.tscCompatible,typescriptVersion- forwarded toreadTsConfig.
Only the upward file search is async. Parsing (including the full
extendschain) 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: nodenext⇒moduleResolution: nodenext).truetargets the latest supported version. Defaultundefined.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 withtscCompatible.
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/fsWriteJsonOptions).
TsConfig Type
interface TsConfig {
extends?: string | string[];
compilerOptions?: CompilerOptions;
include?: string[];
exclude?: string[];
files?: string[];
references?: ProjectReference[];
// ... all TypeScript config options
}