Skip to main content

TypeScript Usage

Hysteria ORM is built with TypeScript in mind, providing full type safety for models, queries, and migrations.

Typescript configuration

{
"compilerOptions": {
// Must set decorators support
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
}

Model Typing

All models and collections are strongly typed. Example:

import { Model, column } from 'hysteria-orm';

class User extends Model {
@column()
declare name: string;
}

Query Type Inference

Query results are automatically typed based on your model definition:

const users = await User.query().many(); // users: User[]

Best Practices

  • Use declare or ${property}! for model properties, since they are not initialized in a constructor.
  • Use enums for status fields.

Next: JavaScript Usage