question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect circularity detection

See original GitHub issue

TypeScript Version: 3.6.2

Search Terms:

  • 7022
  • directly or indirectly in its own initializer

Code

function extent(nums: number[]) {
  let result: [number, number] | null = null;
  for (const num of nums) {
    if (!result) {
      result = [num, num];
    } else {
      const [oldMin, oldMax] = result;
      result = [Math.min(num, oldMin), Math.max(num, oldMax)];
    }
  }
  return result;
}

Expected behavior:

No error.

Actual behavior:

'oldMin' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
'oldMax' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)

I’m really struggling to see where the circularity comes in. The type of result is shown as [number, number] in that branch, so I’d assume destructuring it would result in two number types.

Removing the destructuring and using array accesses is equivalent but produces no error:

function extent(nums: number[]) {
  let result: [number, number] | null = null;
  for (const num of nums) {
    if (!result) {
      result = [num, num];
    } else {
      result = [Math.min(num, result[0]), Math.max(num, result[1])];  // ok
    }
  }
  return result;
}

Playground Link: link

Related Issues:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Jan 27, 2021

BTW, using @JoostK’s example, if you removes the asignation, error goes away… 😆

Removing the assignment removes the circular nature of currentNode, so that’s expected. It ends up being circular due to the involvement of flow typing.

0reactions
MichaelMitchell-atcommented, Apr 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular analysis in systems neuroscience – the dangers of ...
A neuroscientific experiment typically generates a large amount of data, of which only a small fraction is analyzed in detail and presented in...
Read more >
Remove or allow a circular reference - Microsoft Support
To fix the problem, you can move the formula to another cell. Press Ctrl+X to cut the formula, select another cell, and press...
Read more >
How to find (hidden) circular references in your spreadsheet
Excel is capable of detecting circular reference chains. As soon as you click OK on the Circular reference warning dialog, you can find...
Read more >
Blob Detection in openCV works well, but for some reason it ...
I tested your code here and got the same results. But adding params.filterByArea = False. before params.filterByCircularity = True fixed the ...
Read more >
Circular reasoning - Wikipedia
Circular reasoning is a logical fallacy in which the reasoner begins with what they are ... Circularity can be difficult to detect if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found