TypeScript Version: 3.6.2
Search Terms:
- 7022
- directly or indirectly in its own initializer
Code
functionextent(nums: number[]){letresult: [number,number]|null=null;for(constnumofnums){if(!result){result=[num,num];}else{const[oldMin,oldMax]=result;result=[Math.min(num,oldMin),Math.max(num,oldMax)];}}returnresult;}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:
functionextent(nums: number[]){letresult: [number,number]|null=null;for(constnumofnums){if(!result){result=[num,num];}else{result=[Math.min(num,result[0]),Math.max(num,result[1])];// ok}}returnresult;}Playground Link:link
Related Issues:
TypeScript Version: 3.6.2
Search Terms:
Code
Expected behavior:
No error.
Actual behavior:
I'm really struggling to see where the circularity comes in. The type of
resultis shown as[number, number]in that branch, so I'd assume destructuring it would result in twonumbertypes.Removing the destructuring and using array accesses is equivalent but produces no error:
Playground Link:link
Related Issues: