Skip to content

feat: implement generic types on all column types#119

Merged
rmorehig merged 1 commit intotinybirdco:mainfrom
Wyatt-SG:wyatt/branded-type-generics
Feb 26, 2026
Merged

feat: implement generic types on all column types#119
rmorehig merged 1 commit intotinybirdco:mainfrom
Wyatt-SG:wyatt/branded-type-generics

Conversation

@Wyatt-SG
Copy link
Contributor

Summary

  • Add optional generic type parameter (<T extends BaseType = BaseType>) to all 25 simple type validators (t.string(), t.int32(), t.uuid(), etc.)
  • Follows the existing pattern used by t.json<TShape>()
  • Allows users to pass custom types (branded types, opaque types, literal unions) that flow through InferRow, InferEvent, and all inference utilities
  • 100% backwards compatible- all generics default to their base type, zero runtime impact (compiled JS is byte-identical)
type UserId = string & { readonly __brand: "UserId" };

const events = defineDatasource("events", {
  schema: {
    user_id: t.string<UserId>(),  // InferRow → UserId
    name: t.string(),             // InferRow → string (unchanged)
  },
  engine: engine.mergeTree({ sortingKey: ["user_id"] }),
});

Verification

  • pnpm run typecheck
  • pnpm run build (emitted JS identical to before)
  • pnpm -s vitest run src/schema/types.test.ts

@rmorehig
Copy link
Collaborator

Thanks for the PR! 🙏

@rmorehig rmorehig merged commit 4dfddb1 into tinybirdco:main Feb 26, 2026
2 checks passed
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