TypeScript Configuration by silverwind
The `typescript-config-silverwind` package provides a highly opinionated and actively maintained base TypeScript configuration designed for modern JavaScript and TypeScript projects. Currently at version 17.0.0, this configuration package is typically updated to align with major TypeScript releases and evolving best practices, ensuring projects leverage the latest compiler features and strictness improvements. It serves as a foundational configuration, intended to be extended by project-specific `tsconfig.json` files, simplifying TypeScript setup and promoting consistency across repositories. The package emphasizes strong type checking and modern ECMAScript module patterns. Its key differentiator lies in offering a robust, pre-configured set of `compilerOptions` and `include` directives, aiming to reduce boilerplate and common configuration errors for developers by enforcing a consistent and high-quality TypeScript standard. It's often used as a dependency in other `silverwind` configuration packages, demonstrating its role as a core component in a larger ecosystem of opinionated developer tooling.
Common errors
-
error TS6053: File '...' not found.
cause This error often occurs when the `include` or `exclude` arrays in your project's `tsconfig.json` overwrite the base configuration from `typescript-config-silverwind` and unintentionally omit necessary source files or declaration files.fixEnsure your `tsconfig.json`'s `include` patterns explicitly cover all your source files, type declaration files, and other assets required for compilation, as they will completely override the base config's settings. -
error TS7006: Parameter 'x' implicitly has an 'any' type.
cause The `typescript-config-silverwind` configuration likely enables `noImplicitAny`, requiring explicit type annotations for function parameters, variables, or properties where TypeScript cannot infer a specific type.fixAdd explicit type annotations (e.g., `function foo(param: string)`) to resolve these errors. If an `any` type is truly intended, explicitly declare it (e.g., `param: any`) to satisfy the compiler. -
error TS2532: Object is possibly 'undefined'.
cause This configuration enforces `strictNullChecks`, meaning that `null` and `undefined` are not assignable to types unless explicitly included (e.g., `string | null`). Accessing properties on potentially null or undefined values will result in this error.fixImplement proper null/undefined checks (e.g., `if (obj) { obj.property }`), use optional chaining (`obj?.property`), or the non-null assertion operator (`obj!.property`) with caution if you are certain the value is not null/undefined at runtime.
Warnings
- breaking When extending `typescript-config-silverwind`, any `include` or `exclude` arrays defined in your project's `tsconfig.json` will *completely replace* those from the base configuration, rather than merging. This can inadvertently omit files from compilation or include unwanted ones, leading to build errors or unexpected type checking behavior.
- breaking Each major version of `typescript-config-silverwind` likely updates its `compilerOptions` to reflect the latest TypeScript best practices and features. These updates can introduce stricter checks (e.g., `noImplicitAny`, `strictNullChecks`, `noUncheckedIndexedAccess`) that might cause existing code to fail compilation, especially if migrating from a less strict setup.
- gotcha This package is a `tsconfig.json` extender and does not expose any JavaScript/TypeScript modules for direct `import` or `require` statements in application code. Attempting to import symbols from `typescript-config-silverwind` will result in module resolution errors at compile or runtime, as its sole purpose is to configure the TypeScript compiler itself.
Install
-
npm install typescript-config-silverwind -
yarn add typescript-config-silverwind -
pnpm add typescript-config-silverwind
Imports
- Configuration Extension
import { AnyConfig } from 'typescript-config-silverwind';{ "extends": "typescript-config-silverwind" } in tsconfig.json - tsconfig.json 'include' pattern
{ "include": ["src/**/*", "test/**/*"] } in tsconfig.json - Configuration Override
{ "extends": "typescript-config-silverwind", "compilerOptions": { "target": "es2021" } } in tsconfig.json
Quickstart
{
"extends": "typescript-config-silverwind",
"compilerOptions": {
// Override specific compiler options if needed
"outDir": "./dist",
"jsx": "react-jsx"
},
"include": [
"src/**/*",
"types/**/*",
"test/**/*",
"**/.*",
"**/.*/**/*",
"**/.*/**/.*"
],
"exclude": [
"node_modules",
"dist"
]
}