Skip to content

Commit d64646b

Browse files
authored
Allow target-only ES decorators (#57768)
1 parent 1c57060 commit d64646b

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34454,7 +34454,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3445434454
function getDecoratorArgumentCount(node: Decorator, signature: Signature) {
3445534455
return compilerOptions.experimentalDecorators ?
3445634456
getLegacyDecoratorArgumentCount(node, signature) :
34457-
2;
34457+
// Allow the runtime to oversupply arguments to an ES decorator as long as there's at least one parameter.
34458+
Math.min(Math.max(getParameterCount(signature), 1), 2);
3445834459
}
3445934460

3446034461
/**

tests/baselines/reference/esDecorators-arguments.errors.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
esDecorators-arguments.ts(1,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
22
The runtime will invoke the decorator with 2 arguments, but the decorator expects 0.
3-
esDecorators-arguments.ts(2,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
4-
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
53
esDecorators-arguments.ts(4,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
64
The runtime will invoke the decorator with 2 arguments, but the decorator expects 3.
75
esDecorators-arguments.ts(5,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
86
The runtime will invoke the decorator with 2 arguments, but the decorator expects at least 3.
97

108

11-
==== esDecorators-arguments.ts (4 errors) ====
9+
==== esDecorators-arguments.ts (3 errors) ====
1210
@(() => {})
1311
~~~~~~~~~~
1412
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
1513
!!! error TS1238: The runtime will invoke the decorator with 2 arguments, but the decorator expects 0.
1614
@((a: any) => {})
17-
~~~~~~~~~~~~~~~~
18-
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
19-
!!! error TS1238: The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
2015
@((a: any, b: any) => {})
2116
@((a: any, b: any, c: any) => {})
2217
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tests/baselines/reference/tscWatch/programUpdates/updates-diagnostics-and-emit-for-decorators.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ Output::
3939

4040
error TS2318: Cannot find global type 'ClassDecoratorContext'.
4141

42-
a.ts:2:2 - error TS1238: Unable to resolve signature of class decorator when called as an expression.
43-
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
44-
45-
2 @((_) => {})
46-
   ~~~~~~~~~~~
47-
48-
[12:00:20 AM] Found 2 errors. Watching for file changes.
42+
[12:00:20 AM] Found 1 error. Watching for file changes.
4943

5044

5145

0 commit comments

Comments
 (0)