-
Notifications
You must be signed in to change notification settings - Fork 675
Issue implicit any in JS files on widened inferred types from initializers in binding patterns #1064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue implicit any in JS files on widened inferred types from initializers in binding patterns #1064
Changes from 1 commit
c7bf9a2
53ed7bf
ffaebde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
index.js(7,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
index.js(15,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
index.js(37,20): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
index.js(42,15): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
|
||
|
||
==== index.js (4 errors) ==== | ||
/** | ||
* @param {Object} [config] | ||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles] | ||
*/ | ||
export function prepareConfig({ | ||
additionalFiles: { | ||
json = [] | ||
~~~~ | ||
!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
} = {} | ||
} = {}) { | ||
json // string[] | ||
} | ||
|
||
export function prepareConfigWithoutAnnotation({ | ||
additionalFiles: { | ||
json = [] | ||
~~~~ | ||
!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
} = {} | ||
} = {}) { | ||
json | ||
} | ||
|
||
/** @type {(param: { | ||
additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; | ||
}) => void} */ | ||
export const prepareConfigWithContextualSignature = ({ | ||
additionalFiles: { | ||
json = [] | ||
} = {} | ||
} = {})=> { | ||
json // string[] | ||
} | ||
|
||
// Additional repros from https://github.com/microsoft/TypeScript/issues/59936 | ||
|
||
/** | ||
* @param {{ a?: { json?: string[] }}} [config] | ||
*/ | ||
function f1({ a: { json = [] } = {} } = {}) { return json } | ||
~~~~ | ||
!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
|
||
/** | ||
* @param {[[string[]?]?]} [x] | ||
*/ | ||
function f2([[json = []] = []] = []) { return json } | ||
~~~~ | ||
!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,39 @@ | ||
--- old.destructuringParameterDeclaration9(strict=true).errors.txt | ||
+++ new.destructuringParameterDeclaration9(strict=true).errors.txt | ||
@@= skipped -0, +0 lines =@@ | ||
-index.js(15,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
+index.js(7,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
index.js(15,9): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
- | ||
- | ||
-==== index.js (1 errors) ==== | ||
- /** | ||
- * @param {Object} [config] | ||
- * @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles] | ||
- */ | ||
- export function prepareConfig({ | ||
- additionalFiles: { | ||
- json = [] | ||
- } = {} | ||
- } = {}) { | ||
- json // string[] | ||
- } | ||
- | ||
- export function prepareConfigWithoutAnnotation({ | ||
- additionalFiles: { | ||
- json = [] | ||
- ~~~~ | ||
-!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
- } = {} | ||
- } = {}) { | ||
- json | ||
- } | ||
- | ||
- /** @type {(param: { | ||
- additionalFiles?: Partial<Record<"json" | "jsonc" | "json5", string[]>>; | ||
- }) => void} */ | ||
- export const prepareConfigWithContextualSignature = ({ | ||
- additionalFiles: { | ||
- json = [] | ||
- } = {} | ||
- } = {})=> { | ||
- json // string[] | ||
- } | ||
- | ||
- // Additional repros from https://github.com/microsoft/TypeScript/issues/59936 | ||
- | ||
- /** | ||
- * @param {{ a?: { json?: string[] }}} [config] | ||
- */ | ||
- function f1({ a: { json = [] } = {} } = {}) { return json } | ||
- | ||
- /** | ||
- * @param {[[string[]?]?]} [x] | ||
- */ | ||
- function f2([[json = []] = []] = []) { return json } | ||
- | ||
+<no content> | ||
+index.js(37,20): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
+index.js(42,15): error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
+ | ||
+ | ||
+==== index.js (4 errors) ==== | ||
/** | ||
* @param {Object} [config] | ||
* @param {Partial<Record<'json' | 'jsonc' | 'json5', string[]>>} [config.additionalFiles] | ||
@@= skipped -8, +11 lines =@@ | ||
export function prepareConfig({ | ||
additionalFiles: { | ||
json = [] | ||
+ ~~~~ | ||
+!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also tried porting this and hit these same issues. I'm pretty sure these are exactly the things that we are aiming to prevent, but now I think the fix doesn't quite work anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a look at this tomorrow~ then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR aims to issue implicit any error - and it does that... to some extent 😉 It is overly eager though. From what I can see, this one is still not handled by the reparser - and that's why we are seeing errors here. The compiler thinks it doesn't have a type annotation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @a-tarasyuk had a recent PR that improves handling of destructured parameters. Do things improve if you merge from main? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! |
||
} = {} | ||
} = {}) { | ||
json // string[] | ||
@@= skipped -32, +34 lines =@@ | ||
* @param {{ a?: { json?: string[] }}} [config] | ||
*/ | ||
function f1({ a: { json = [] } = {} } = {}) { return json } | ||
+ ~~~~ | ||
+!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
|
||
/** | ||
* @param {[[string[]?]?]} [x] | ||
*/ | ||
function f2([[json = []] = []] = []) { return json } | ||
+ ~~~~ | ||
+!!! error TS7031: Binding element 'json' implicitly has an 'any[]' type. | ||
|
Uh oh!
There was an error while loading. Please reload this page.