tsdef is a TypeScript utility library that provides a curated collection of common type definitions and aliases to simplify complex type patterns and enhance code readability in TypeScript projects. It aims to reduce boilerplate and improve type safety by offering widely applicable utility types such as `Nullable`, `NonNull`, `MaybePromise`, and various `Props` modifiers (e.g., `NonNullProps`, `WritableProps`). The current stable version is 0.0.14. As a pre-1.0 release, its release cadence is likely irregular, and breaking changes might occur more frequently than with a semantically versioned stable library. It differentiates itself by being a pure type-only library, meaning it introduces zero runtime overhead and focuses exclusively on type-system improvements, making it suitable for projects that prioritize strict type integrity without adding to the JavaScript bundle size.
npm install tsdefVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the usage of `Nullable`, `NonNull`, `MaybePromise`, and `MaybeArray` type utilities from `tsdef` to handle common TypeScript type patterns, showcasing how to define types that explicitly allow or disallow null/undefined, or encapsulate potential promises or arrays.
Pin the exact version of `tsdef` in your `package.json` (e.g., `"tsdef": "0.0.14"`) and manually review release notes before updating to new versions, especially for critical production applications.
Ensure installation with `npm install -D tsdef` or `yarn add -D tsdef`. If already installed incorrectly, move it from `dependencies` to `devDependencies` in `package.json`.
Be mindful of potential naming collisions. If a conflict occurs, consider importing with an alias (e.g., `import { Nullable as TsdefNullable } from 'tsdef';`) or evaluating if a native TypeScript utility type serves the same purpose.Ensure `tsdef` is installed as a dev dependency: `npm install -D tsdef` or `yarn add -D tsdef`. Also, verify your `tsconfig.json` includes `"typeRoots": ["./node_modules/@types", "./node_modules"]` or similar settings to allow TypeScript to discover type declarations.
Refactor your code to ensure that values assigned to `NonNull` types are indeed guaranteed to be non-null. This often involves null checks (`if (value !== null)`) or using optional chaining (`?.`) and nullish coalescing (`??`) operators before assignment or usage.
If you intend for properties to be required *and* non-nil, combine `NonNilProps<T>` with `RequiredProps<T>` or directly use `Required<NonNilProps<T>>` to achieve the desired strictness.
No dependency data recorded yet.