Allow target-only ES decorators (#57768)

This commit is contained in:
Ron Buckton 2024-03-14 14:44:40 -04:00 committed by GitHub
parent 1c5706092e
commit d64646b3fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 14 deletions

View File

@ -34454,7 +34454,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getDecoratorArgumentCount(node: Decorator, signature: Signature) {
return compilerOptions.experimentalDecorators ?
getLegacyDecoratorArgumentCount(node, signature) :
2;
// Allow the runtime to oversupply arguments to an ES decorator as long as there's at least one parameter.
Math.min(Math.max(getParameterCount(signature), 1), 2);
}
/**

View File

@ -1,22 +1,17 @@
esDecorators-arguments.ts(1,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 0.
esDecorators-arguments.ts(2,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
esDecorators-arguments.ts(4,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 3.
esDecorators-arguments.ts(5,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects at least 3.
==== esDecorators-arguments.ts (4 errors) ====
==== esDecorators-arguments.ts (3 errors) ====
@(() => {})
~~~~~~~~~~
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
!!! error TS1238: The runtime will invoke the decorator with 2 arguments, but the decorator expects 0.
@((a: any) => {})
~~~~~~~~~~~~~~~~
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
!!! error TS1238: The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
@((a: any, b: any) => {})
@((a: any, b: any, c: any) => {})
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -39,13 +39,7 @@ Output::
error TS2318: Cannot find global type 'ClassDecoratorContext'.
a.ts:2:2 - error TS1238: Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
2 @((_) => {})
   ~~~~~~~~~~~
[12:00:20 AM] Found 2 errors. Watching for file changes.
[12:00:20 AM] Found 1 error. Watching for file changes.