mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 06:20:23 -06:00
Merge pull request #6129 from pimterry/decorator-overload-msg
Improve decorator on overload error message
This commit is contained in:
commit
ee50adbc85
@ -15563,7 +15563,12 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
if (!nodeCanBeDecorated(node)) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
|
||||
if (node.kind === SyntaxKind.MethodDeclaration && !ts.nodeIsPresent((<MethodDeclaration>node).body)) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload);
|
||||
}
|
||||
else {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Decorators_are_not_valid_here);
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) {
|
||||
const accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, <AccessorDeclaration>node);
|
||||
|
||||
@ -795,6 +795,10 @@
|
||||
"category": "Error",
|
||||
"code": 1248
|
||||
},
|
||||
"A decorator can only decorate a method implementation, not an overload.": {
|
||||
"category": "Error",
|
||||
"code": 1249
|
||||
},
|
||||
"'with' statements are not allowed in an async function block.": {
|
||||
"category": "Error",
|
||||
"code": 1300
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts(4,5): error TS1249: A decorator can only decorate a method implementation, not an overload.
|
||||
|
||||
|
||||
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethodOverload1.ts (1 errors) ====
|
||||
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
|
||||
class C {
|
||||
@dec
|
||||
~
|
||||
!!! error TS1249: A decorator can only decorate a method implementation, not an overload.
|
||||
method()
|
||||
method() { }
|
||||
}
|
||||
16
tests/baselines/reference/decoratorOnClassMethodOverload1.js
Normal file
16
tests/baselines/reference/decoratorOnClassMethodOverload1.js
Normal file
@ -0,0 +1,16 @@
|
||||
//// [decoratorOnClassMethodOverload1.ts]
|
||||
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
|
||||
class C {
|
||||
@dec
|
||||
method()
|
||||
method() { }
|
||||
}
|
||||
|
||||
//// [decoratorOnClassMethodOverload1.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.method = function () { };
|
||||
return C;
|
||||
}());
|
||||
@ -0,0 +1,9 @@
|
||||
// @target: ES5
|
||||
// @experimentaldecorators: true
|
||||
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
|
||||
class C {
|
||||
@dec
|
||||
method()
|
||||
method() { }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user