TypeScript types

Read this page in the documentation

TypeScript types Prorm ships typed model definitions: declare a class with typed properties, and InferAttributes / InferCreationAttributes derive the shapes for reading and creating from that one declaration. No second interface to keep in sync. Model takes two type parameters: the attributes of a loaded row, and the creation attributes accepted by create() / build(). The helper types Type | Use | --- | --- | CreationOptional<T> | Optional at create time, always present when read — auto-increment ids, defaulted columns, timestamps. | NonAttribute<T> | This property is not a database column — eager-loaded associations, getters, computed values. Excluded from both inferred shapes. | ForeignKey<T> | Brands a foreign-key column so its type is tied to the key it references: declare userId: ForeignKey<User['id']>. | InferAttributes<T> | Every property except NonAttribute ones. | InferCreationAttributes<T> | Same, with CreationOptional properties made optional. | PartialBy<T, K> | T with K optional. | RequiredBy<T, K> | T with K required. | ModelStatic<T> | The static side of a model — name, tableName, attributes, associations, getTableName(), getPrimaryKeyAttribute(). Use it to type a function that takes any model. | ModelOptions | The options object accepted by define() / @Table. | The declare keyword matters. Without it TypeScript emits a real class field that shadows the model's own accessor at runtime, and reads come back undefined. declare is a type-only declaration and emits nothing. Writing a function over any model Typing the ORM's own options Every option object is exported and can be imported directly: Building the options object separately, typed, is a good habit for anything constructed conditionally — the compiler checks it once, at the point you write it. tsconfig Decorator-based models need: strict: true is what makes CreationOptional and the nullable column types worth anything — without strictNullChecks, string | null and string are the same to the compiler. Honest limits These helpers are compile-time conveniences over a runtime that is dynamic by nature. Two things they do not do: InferAttributes does not consult your data types. It reads the declared TypeScript property types. Declaring declare age: string beside age: { type: DataTypes.INTEGER() } compiles happily and hands you a number at runtime. Keep the two in step yourself. NonAttribute<T> is T. It is a marker for the inference types, not a distinct type — nothing stops you assigning across it. Where the guarantee matters, back the types with a runtime check: Validation runs against the actual values. Related reading Defining models Data types Decorators Querying — FindOptions in full