-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improved
FindOptionsWhere
behavior with union types (#9607)
* test: add test that where condition can accepts LessThan with Union * fix: allow FindOptionsWhere to accept LessThan with Union * added comment and simplified the type --------- Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
- Loading branch information
Showing
3 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src" | ||
|
||
export type ValueUnion = 1 | 2 | 3 | ||
|
||
@Entity() | ||
export class Test { | ||
@PrimaryGeneratedColumn({ unsigned: true }) | ||
id: number | ||
|
||
@Column() | ||
value: ValueUnion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import "reflect-metadata" | ||
import { expect } from "chai" | ||
import { Test, ValueUnion } from "./entity/Test" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { LessThan } from "../../../src" | ||
|
||
describe("github issues > #9152 Can't use LessThan for Union field", () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [Test], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should not raise TypeScript error when LessThan with Union is passed to FindOptionsWhere", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
await connection.getRepository(Test).save({ | ||
value: 1, | ||
}) | ||
|
||
const value = 2 as ValueUnion | ||
|
||
const count = await connection.getRepository(Test).countBy({ | ||
value: LessThan(value), | ||
}) | ||
|
||
expect(count).to.eq(1) | ||
}), | ||
)) | ||
}) |