Closed burtek closed 1 month ago
I'll fix this as part of https://github.com/microsoft/TypeScript/pull/59924
@Andarist ok, thanks. I guess it's gonna go out as 5.6 patch bump?
@burtek in the end I decided to create a separate PR for this one since I was able to fix this independently and the other PR raises some design questions. The fix is available here: https://github.com/microsoft/TypeScript/pull/59975
As to your question, this is a recent regression so I'd advocate to bacport a fix to 5.6 but that's up to the TS team.
This issue actually existed before 5.6, but only for array binding patterns (playground link):
/**
* @param {[[string[]?]?]} [x]
*/
function f1([[json = []] = []] = []) { return json } // Implicit any[] error on json binding element
In 5.6 we aligned array and object literal padding and the issue then showed up in object binding patterns as well:
/**
* @param {{ a?: { json?: string[] }}} [x]
*/
function f2({ a: { json = [] } = {} } = {}) { return json } // Implicit any[] error on json binding element
The culprit here is logic we have in widenTypeInferredFromInitializer
to issue no-implicit-any errors in JS files. We shouldn't be issuing these errors when we're obtaining the implied type for a binding pattern. I'll put up a PR to fix. Unfortunately the fix in #59975 isn't the right one.
π Search Terms
Binding element implicitly has an any type 7031
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?strictNullChecks=true&target=9&suppressImplicitAnyIndexErrors=true&ts=5.6.2&filetype=js#code/PQKhCgAIUgBAHAhgJ0QW0gbwPICMBWApgMYAuAvpANrED2AdgGYCWA5gLpQwIrpYAKKUs0QAbADwAlErWQATcQHJ8AZwaLIAH0jK19Yhu26GAVkUAaSCtLJm9VlXYA+J5RoMWrAHSI5c5sIMYgBizKKEKpzQwOCEAB7wsqSQjACu+oH0kPDIhEi5AMIebAAUmFCQlb7+mSFhEQBcWBWVrZCqDJAAvNRRrZQ9mOTgA1jkAJTNbXT0auFeorSsJR304yNAA
π» Code
π Actual behavior
json
is errored asBinding element 'json' implicitly has an 'any[]' type.(7031)
even though it's typed asstring[]
π Expected behavior
No error expected, as
json
is typed asstring[]
Additional information about the issue
This worked well in 5.5.4 but broke with upgrade to 5.6.2. It works correctly in .ts file, but breaks in .js file with JSDoc.