Skip to content

Can't use LessThan for Union field #9152

@tsugitta

Description

@tsugitta

Issue Description

if a field is defined as Union like 1 | 2 | 3 or 'foo' | 'bar', operators LessThan, MoreThan, etc. raises a type error.

code example:

import { Entity, Column, getConnection, LessThan } from "typeorm";

type ValueType = 1 | 2 | 3;

@Entity()
export class User {
  @Column()
  foo: ValueType;
}

const repository = getConnection().getRepository(User);

const value = 3 as ValueType;

repository.findBy({
  foo: LessThan(value)
});

Expected Behavior

works as if the field is defined as number

Actual Behavior

Type 'FindOperator<1 | 2 | 3>' is not assignable to type '1 | 2 | 3 | FindOperator<1> | FindOperator<2> | FindOperator<3> | undefined'.
  Type 'FindOperator<1 | 2 | 3>' is not assignable to type 'FindOperator<1>'.
    Type '1 | 2 | 3' is not assignable to type '1'.
      Type '2' is not assignable to type '1'.ts(2322)

Steps to Reproduce

CodeSandbox

My Environment

Dependency Version
Operating System
Node.js version
Typescript version 4.4.4
TypeORM version 0.3.6

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions