Created
November 3, 2025 13:02
-
-
Save kriszyp/fbe13c69d175f691d10f4cedfca0dcd2 to your computer and use it in GitHub Desktop.
Declaring of table with fields in TS, and inferred types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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