Give a more helpful error message when users try decorating using expressions that take no arguments.

This commit is contained in:
Daniel Rosenwasser
2017-09-27 20:30:10 -07:00
parent d407f14e86
commit b029857528
2 changed files with 9 additions and 0 deletions

5
src/compiler/checker.ts Normal file → Executable file
View File

@@ -16381,6 +16381,11 @@ namespace ts {
return resolveUntypedCall(node);
}
if (callSignatures.length === 1 && callSignatures[0].parameters.length === 0) {
error(node, Diagnostics.A_decorator_function_must_accept_some_number_of_arguments_but_this_expression_takes_none_Did_you_mean_to_call_it_first);
return resolveErrorCall(node);
}
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
if (!callSignatures.length) {
let errorInfo: DiagnosticMessageChain;

4
src/compiler/diagnosticMessages.json Normal file → Executable file
View File

@@ -907,6 +907,10 @@
"category": "Error",
"code": 1328
},
"A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first?": {
"category": "Error",
"code": 1329
},
"Duplicate identifier '{0}'.": {
"category": "Error",