Skip to content

Conversation

@toiroakr
Copy link
Contributor

Summary

Make Tailordb.Client constructor parameter overridable through declaration merging, allowing
library consumers to customize the client configuration type while maintaining backward
compatibility.

Motivation

Previously, the Tailordb.Client constructor had a fixed parameter type with only an optional
namespace field. This design made it impossible for library consumers to:

  • Override default field to narrow (e.g., make namespace "main-db" | "sub-db")

This PR introduces a flexible type system that allows consumers to extend or override the
client configuration through TypeScript's declaration merging.

Changes

Type System

  • Added UserClientConfig interface: Empty by default, can be extended by consumers via
    declaration merging
  • Added DefaultClientConfig interface: Contains the default namespace?: string field
  • Created ClientConfig type: Merges UserClientConfig with DefaultClientConfig, where
    UserClientConfig takes precedence

Testing Infrastructure

  • Set up Vitest with type checking support
  • Added comprehensive type tests covering 4 scenarios:
    • default: Empty UserClientConfig (backward compatible)
    • required-field: Adding a required field (apiKey: string)
    • optional-field: Adding an optional field (timeout?: number)
    • override: Overriding default field optionality (namespace: string)

Test Configuration

  • Configured Vitest with 4 separate projects for isolated type testing
  • Each test scenario has its own tsconfig.json for proper type isolation

@toiroakr toiroakr requested a review from a team as a code owner October 22, 2025 06:09
interface UserClientConfig {}

interface DefaultClientConfig {
namespace: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this technically qualifies as a breaking change, because omitting it would already have caused an error, nothing actually changes in practice.

@toiroakr toiroakr closed this Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants