Skip to content

typescript definition: function inside operator inside where #11079

Closed

Description

@fareshan

This does not work:

import { col, fn, Op, where } from "sequelize/types";

const whereName = where(
      fn("unaccent", col("name")),
      { [Op.iLike]: fn("unaccent", "john") },
);

The typescript error:

Argument of type '{ [Op.iLike]: Fn; }' is not assignable to parameter of type 'LogicType'.
  Type '{ [Op.iLike]: Fn; }' is not assignable to type 'WhereOperators'.
    Types of property '[Op.iLike]' are incompatible.
      Type 'Fn' is not assignable to type 'string | Literal | AnyOperator | AllOperator | undefined'.
        Property '[Op.all]' is missing in type 'Fn' but required in type 'AllOperator'.ts(2345)
model.d.ts(137, 3): '[Op.all]' is declared here.

Environment

sequelize-typescript: 1.0.0-beta.3
Dialect:

  • mysql
  • [ X ] postgres
  • sqlite
  • mssql
  • any
    Dialect library version: pg version 6.4.2
    Database version: 9.6.12
    Sequelize version: 5.8.10
    Node Version: 8.11.4
    OS: macOS 10.14.3
    TypeScript version: 3.4.3 (or 3.3.3 same issue)
    Tested with latest release:
  • No
  • [ X ] Yes, specify that version: 5.8.10

Activity

  1. added
    typescript
    on Jul 25, 2019
  2. DakotaLarson commented on Aug 28, 2020

    @DakotaLarson

    For those who reach this in the future, I was able to resolve the issue:
    attributes: [[fn("max", col("colC")), "theAlias"], "colA", "colB"]. It's noted in the TS definition, but it's challenging to read. Use an array for this function argument and pass an alias as the second argument.

  3. github-actions commented on Nov 9, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions