computed length property reports a constant length 1 to the lsp
Version: Deno 1.40.4
In a provided minimal example the length property shows a squiggly in the IDE anywhere where an attempt is made to assert the computed length with anything but 1.
The error popup notifies "This comparison appears to be unintentional because the types '1' and '2' have no overlap." and reports as if the length has a type of a single 1: (property) SetWithContentEquality<T extends object>.length: 1
Strangely, an editor-invoked test run completes the test with no errors and succeeds.
However, manual deno test will report an error instead:
error: TS2367 [ERROR]: This comparison appears to be unintentional because the types '1' and '2' have no overlap.
assert(set.length == 2);
~~~~~~~~~~~~~~~
at file:///deno-length-getter/main_test.ts:16:10
Minimal example to reproduce the bug: https://github.com/king8fisher/deno-bug-reports/tree/main/22384-deno-length-getter
This occurs in the typescript playground (see here).
Maybe use assertEquals instead? (ex. assertEquals(set.length, 1)) You'll get better errors on failure when that happens too.
That's an interesting catch! I will certainly fix my assert, thanks @dsherret. I might be hitting just how the type system is designed when the == or === comparisons are utilized.