-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
1 - XS (<= 1 day)
-
4994
How frequently does the bug occur?
Seen once
Description
Our types declare that the min, max and sum can return null:
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
min(property?: string): number | Date | null; max(property?: string): number | Date | null; sum(property?: string): number | null; avg(property?: string): number;
But the implementation shows that min, max and avg actually return undefined when there are no objects in the collection:
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
const realm = new Realm({ schema: [{ name: "Item", properties: { value: "int" } }], }); realm.objects("Item").min("value"); // returns `undefined` realm.objects("Item").max("value"); // returns `undefined` realm.objects("Item").avg("value"); // returns `undefined` realm.objects("Item").sum("value"); // returns `0`
We are actually testing, to ensure this behaviour ☝️
https://github.com/realm/realm-js/blob/master/tests/js/list-tests.js#L1389-L1392
Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
10.21.1
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
Tested on Node.js
Build environment
No response
Cocoapods version
No response