Incorrect circularity detection
See original GitHub issueTypeScript 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:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.A new one in 4.7.0-beta https://github.com/microsoft/TypeScript/issues/48708