Repository navigation
Description
While converting test/unit/sql to TypeScript (#18565), we found four things that work at runtime but are missing from, or rejected by, the public model typings. #18565 deliberately leaves the typings alone, because each one is a behaviour decision: either widen the typings to match the runtime, or deprecate the runtime behaviour. The tests use @ts-expect-error comments that point to this issue.
Nothing has been decided yet. This issue collects the four gaps so maintainers can decide per item.
Line numbers are as of 66b06e8.
1. Lowercase onDelete / onUpdate values
ReferentialAction (packages/core/src/model.d.ts:1700) only allows the uppercase forms ('CASCADE' | 'RESTRICT' | 'SET DEFAULT' | 'SET NULL' | 'NO ACTION'). The SQL generation uppercases the value anyway (query-generator-internal.ts:193-197 and the MySQL attributeToSql), so onDelete: 'cascade' produces ON DELETE CASCADE.
Options: accept the lowercase variants in the type (e.g. ReferentialAction | Lowercase<ReferentialAction>), or keep the type strict and treat lowercase as undocumented.
Test: test/unit/sql/add-column.test.ts and change-column.test.ts (lowercase 'cascade').
2. The first attribute option
attributeToSql appends FIRST when attribute.first is set, in mysql (query-generator-typescript.internal.ts:237), mariadb (:243), ibmi (:295) and snowflake (:236). It is used for addColumn(..., { first: true }) on MySQL/MariaDB. The option is not in AttributeOptions, so it can't be used from TypeScript without an error.
Options: type it, either as a regular attribute option documented as dialect-specific or only on the addColumn path, or drop it. It might also be worth checking whether FIRST is valid at all for ibmi and snowflake.
Test: test/unit/sql/add-column.test.ts ("properly generate alter queries with FIRST").
3. Timestamp attributes without a type
Users can declare createdAt / updatedAt / deletedAt to change only their options (e.g. createdAt: { field: 'created_at' }), and Sequelize fills in the DATE type (model-definition.ts:438 has its own @ts-expect-error -- this property is not mandatory in timestamp attributes). The public AttributeOptions type requires type, so this is rejected in TypeScript.
Options: make type optional for the configured timestamp attribute names (hard to express when they're renamed via createdAt: 'created'), or require type and document it.
Test: test/unit/sql/insert.test.ts ("bulkCreate › bulk create with onDuplicateKeyUpdate").
4. attribute as an alias of name in index fields
The legacy addIndexQuery accepts { attribute: 'fieldA' } in fields and copies it to name (query-generator.js:717). IndexField (query-interface.d.ts:81) only has name. The return type of showIndex (IndexFieldDescription) uses attribute, which may be where the alias comes from.
Options: type attribute as a deprecated alias, or deprecate and later remove it at runtime.
Test: test/unit/sql/index.test.ts ("addIndex › type and using").
Related: the query generator typings themselves (selectQuery, insertQuery, updateQuery, addIndexQuery) are fixed in #18565. Those had no behaviour question, the typings were just wrong.
Activity
meta: track typing gaps in #18567 and document the addIndex rawTablen…
meta: track typing gaps in #18567 and document the addIndex rawTablen…
meta: track typing gaps in #18567 and document the addIndex rawTablen…
meta: track typing gaps in #18567 and document the addIndex rawTablen…