-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Give a more helpful error message for certain decorators with too many arguments #18811
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b029857
Give a more helpful error message when users try decorating using exp…
DanielRosenwasser fbbf3d2
Accepted baselines.
DanielRosenwasser 966f370
Use a better check.
DanielRosenwasser 08ef6e4
Accepted baselines.
DanielRosenwasser 86315ed
Added test and adjusted reporting logic.
DanielRosenwasser 803b566
Accepted baselines.
DanielRosenwasser 96bb796
Improve error message for uncalled decorators.
DanielRosenwasser 392cd61
Added a test for an 'any'-type decorator.
DanielRosenwasser 35cfcff
Use 'getTextOfNode'.
DanielRosenwasser 7750a88
Accepted baselines.
DanielRosenwasser 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 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 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
Empty file.
This file contains 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 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
174 changes: 174 additions & 0 deletions
174
tests/baselines/reference/potentiallyUncalledDecorators.errors.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1,174 @@ | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(4,5): error TS1329: 'Input' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@Input()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(35,1): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(37,5): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(38,5): error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(41,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
Type 'OmniDecorator' is not assignable to type 'typeof B'. | ||
Type 'OmniDecorator' provides no match for the signature 'new (): B'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(43,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
Unable to resolve signature of property decorator when called as an expression. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(44,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(47,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
Type 'OmniDecorator' is not assignable to type 'typeof C'. | ||
Type 'OmniDecorator' provides no match for the signature 'new (): C'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(49,5): error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(50,5): error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(53,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
Type 'OmniDecorator' is not assignable to type 'typeof D'. | ||
Type 'OmniDecorator' provides no match for the signature 'new (): D'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(55,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
Unable to resolve signature of property decorator when called as an expression. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(56,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(59,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
Type 'OmniDecorator' is not assignable to type 'typeof E'. | ||
Type 'OmniDecorator' provides no match for the signature 'new (): E'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(61,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
Unable to resolve signature of property decorator when called as an expression. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(62,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(65,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
Type 'OmniDecorator' is not assignable to type 'typeof F'. | ||
Type 'OmniDecorator' provides no match for the signature 'new (): F'. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
Unable to resolve signature of property decorator when called as an expression. | ||
tests/cases/compiler/potentiallyUncalledDecorators.ts(68,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
|
||
|
||
==== tests/cases/compiler/potentiallyUncalledDecorators.ts (19 errors) ==== | ||
// Angular-style Input/Output API: | ||
declare function Input(bindingPropertyName?: string): any; | ||
class FooComponent { | ||
@Input foo: string; | ||
~~~~~~ | ||
!!! error TS1329: 'Input' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@Input()'? | ||
} | ||
|
||
// Glimmer-style tracked API: | ||
declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } | ||
|
||
class Person { | ||
@tracked person; any; | ||
} | ||
|
||
class MultiplyByTwo { | ||
args: any; | ||
@tracked('args') | ||
get multiplied() { | ||
return this.args.number * 2; | ||
} | ||
} | ||
|
||
// Other fun stuff. | ||
|
||
interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { | ||
} | ||
|
||
declare function noArgs(): OmniDecorator; | ||
declare function allRest(...args: any[]): OmniDecorator; | ||
declare function oneOptional(x?: any): OmniDecorator; | ||
declare function twoOptional(x?: any, y?: any): OmniDecorator; | ||
declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; | ||
declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; | ||
declare const anyDec: any; | ||
|
||
@noArgs | ||
~~~~~~~ | ||
!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
class A { | ||
@noArgs foo: any; | ||
~~~~~~~ | ||
!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
@noArgs bar() { } | ||
~~~~~~~ | ||
!!! error TS1329: 'noArgs' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@noArgs()'? | ||
} | ||
|
||
@allRest | ||
~~~~~~~~ | ||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof B'. | ||
!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): B'. | ||
class B { | ||
@allRest foo: any; | ||
~~~~~~~~ | ||
!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. | ||
@allRest bar() { } | ||
~~~~~~~~ | ||
!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
} | ||
|
||
@oneOptional | ||
~~~~~~~~~~~~ | ||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof C'. | ||
!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): C'. | ||
class C { | ||
@oneOptional foo: any; | ||
~~~~~~~~~~~~ | ||
!!! error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? | ||
@oneOptional bar() { } | ||
~~~~~~~~~~~~ | ||
!!! error TS1329: 'oneOptional' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@oneOptional()'? | ||
} | ||
|
||
@twoOptional | ||
~~~~~~~~~~~~ | ||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof D'. | ||
!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): D'. | ||
class D { | ||
@twoOptional foo: any; | ||
~~~~~~~~~~~~ | ||
!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. | ||
@twoOptional bar() { } | ||
~~~~~~~~~~~~ | ||
!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
} | ||
|
||
@threeOptional | ||
~~~~~~~~~~~~~~ | ||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof E'. | ||
!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): E'. | ||
class E { | ||
@threeOptional foo: any; | ||
~~~~~~~~~~~~~~ | ||
!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. | ||
@threeOptional bar() { } | ||
~~~~~~~~~~~~~~ | ||
!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
} | ||
|
||
@oneOptionalWithRest | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression. | ||
!!! error TS1238: Type 'OmniDecorator' is not assignable to type 'typeof F'. | ||
!!! error TS1238: Type 'OmniDecorator' provides no match for the signature 'new (): F'. | ||
class F { | ||
@oneOptionalWithRest foo: any; | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1236: The return type of a property decorator function must be either 'void' or 'any'. | ||
!!! error TS1236: Unable to resolve signature of property decorator when called as an expression. | ||
@oneOptionalWithRest bar() { } | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. | ||
!!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. | ||
} | ||
|
||
@anyDec | ||
class G { | ||
@anyDec foo: any; | ||
@anyDec bar() { } | ||
} | ||
|
||
export { }; | ||
|
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.
should you also check that the return type is callable/
any
to ensure your suggestion of calling it is warranted.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.
any
is accounted for - it's an uncalled function call. It also has no signatures.