Type checking for tsconfig.json
npm install types-tsconfigType checking for tsconfig.json.
_If I should maintain this repo, please ⭐️_
_DM me on Twitter if you have questions or suggestions._
---
This package uses [zod]() to parse and type-guard a TSConfigJSON object.
``sh`
yarn add types-tsconfig
`sh`
npm install types-tsconfig
`sh`
pnpm add types-tsconfig
The isTSConfigJSON function is a type guard that checks if an object is a valid TSConfigJSON object.
`ts
import { isTSConfigJSON, TSConfigJSON } from "types-tsconfig";
const config = {
$schema: "https://json.schemastore.org/tsconfig",
extends: "@autosoft/tsconfig",
compilerOptions: {
outDir: ".auto/build",
rootDirs: [
"source"
]
},
files: [
"source/index.ts"
]
};
if(isTSConfigJSON(config)) {
// config is TSConfigJSON
}
`
The parseTSConfigJSON function parses an object into a TSConfigJSON object. If the object is a valid TSConfigJSON object, it will be returned, otherwise undefined will be returned.
`ts
import { parseTSConfigJSON, TSConfigJSON } from "types-tsconfig";
const config = {
invalid: "config"
};
const result = parseTSConfigJSON(config); // undefined
`
Additionally, a constant fileName is exported as "tsconfig.json":
`ts
import { fileName } from "types-tsconfig";
console.log(fileName); // "tsconfig.json"
``
- type-fest: A collection of essential TypeScript types
- zod: TypeScript-first schema declaration and validation library with static type inference
- autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
MIT - _MIT License_
- types-json: Type checking for JSON objects
- types-pkg-json: Type checking for package.json
- types-eslintrc: Type checking for .eslintrc.json