Skip to content

Instantly share code, notes, and snippets.

@kriszyp
Created November 3, 2025 13:02
Show Gist options
  • Save kriszyp/fbe13c69d175f691d10f4cedfca0dcd2 to your computer and use it in GitHub Desktop.
Save kriszyp/fbe13c69d175f691d10f4cedfca0dcd2 to your computer and use it in GitHub Desktop.
Declaring of table with fields in TS, and inferred types
import { Indexed, PrimaryKey, NonNullable, types, table } from 'harper';
// is it better to namespace these ask users to:
// const { Indexed, PrimaryKey, NonNullable } = types;
export class Product extends table({ name: 'Product', fields: {
id: PrimaryKey(Number),
name: Indexed(String),
price: NonNullable(Number),
tags: [String],
}}) {
async get(target: RequestTarget) {
const product = super.get(target);
const name = product.name; // type system recognizes this is a string
return name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment