From b029857528ba37ccec4d09afca69ab24cf8c8fe5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 Sep 2017 20:30:10 -0700 Subject: [PATCH 01/10] Give a more helpful error message when users try decorating using expressions that take no arguments. --- src/compiler/checker.ts | 5 +++++ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 9 insertions(+) mode change 100644 => 100755 src/compiler/checker.ts mode change 100644 => 100755 src/compiler/diagnosticMessages.json diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts old mode 100644 new mode 100755 index d89247b70f978..b342003cb5902 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json old mode 100644 new mode 100755 index bf8fcdc4f84b3..193c6879b1364 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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", From fbbf3d22e398ad894be3a79c85f2769175c41826 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 Sep 2017 20:56:59 -0700 Subject: [PATCH 02/10] Accepted baselines. --- tests/baselines/reference/decoratorOnClassMethod6.errors.txt | 4 ++-- .../baselines/reference/decoratorOnClassProperty11.errors.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt index 530e86117eeac..ab09a01f19bf7 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): class C { @dec ["method"]() {} ~~~~ -!!! error TS1241: Unable to resolve signature of method decorator when called as an expression. +!!! error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt index 2a72fefa53ede..8e778300aa6c9 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1240: Unable to resolve signature of property decorator when called as an expression. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts( class C { @dec prop; ~~~~ -!!! error TS1240: Unable to resolve signature of property decorator when called as an expression. +!!! error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? } \ No newline at end of file From 966f370712a5c16a527ce098acad0ff175262926 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 29 Sep 2017 16:42:30 -0700 Subject: [PATCH 03/10] Use a better check. --- src/compiler/checker.ts | 15 +++++++++++++-- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) mode change 100755 => 100644 src/compiler/checker.ts mode change 100755 => 100644 src/compiler/diagnosticMessages.json diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts old mode 100755 new mode 100644 index b342003cb5902..3760dd6a19f90 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16381,8 +16381,8 @@ 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); + if (isPotentiallyUncalledDecorator(node, callSignatures)) { + error(node, Diagnostics.This_function_cannot_be_used_as_a_decorator_Did_you_mean_to_call_it_first); return resolveErrorCall(node); } @@ -16398,6 +16398,17 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray, headMessage); } + /** + * Sometimes, we have a decorator that could accept zero arguments, + * but is receiving too many arguments as part of the decorator invocation. + * In those cases, a user may have meant to *call* the expression before using it as a decorator. + */ + function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: Signature[]) { + return signatures.length && every(signatures, signature => + signature.minArgumentCount === 0 && + signature.parameters.length < getEffectiveArgumentCount(decorator, /*args*/ undefined, signature)) + } + /** * This function is similar to getResolvedSignature but is exclusively for trying to resolve JSX stateless-function component. * The main reason we have to use this function instead of getResolvedSignature because, the caller of this function will already check the type of openingLikeElement's tagName diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json old mode 100755 new mode 100644 index 193c6879b1364..722985aac78c1 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -907,7 +907,7 @@ "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?": { + "This function cannot be used as a decorator. Did you mean to call it first?": { "category": "Error", "code": 1329 }, From 08ef6e4bea636cdabe05fd65cd07bc40f4924b9d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 29 Sep 2017 16:42:46 -0700 Subject: [PATCH 04/10] Accepted baselines. --- src/compiler/checker.ts | 2 +- tests/baselines/reference/decoratorOnClassMethod6.errors.txt | 4 ++-- .../baselines/reference/decoratorOnClassProperty11.errors.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3760dd6a19f90..a272ac15e72e6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16406,7 +16406,7 @@ namespace ts { function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: Signature[]) { return signatures.length && every(signatures, signature => signature.minArgumentCount === 0 && - signature.parameters.length < getEffectiveArgumentCount(decorator, /*args*/ undefined, signature)) + signature.parameters.length < getEffectiveArgumentCount(decorator, /*args*/ undefined, signature)); } /** diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt index ab09a01f19bf7..befe582025c86 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: This function cannot be used as a decorator. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): class C { @dec ["method"]() {} ~~~~ -!!! error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? +!!! error TS1329: This function cannot be used as a decorator. Did you mean to call it first? } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt index 8e778300aa6c9..771ca46b572d4 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: This function cannot be used as a decorator. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts( class C { @dec prop; ~~~~ -!!! error TS1329: A decorator function must accept some number of arguments, but this expression takes none. Did you mean to call it first? +!!! error TS1329: This function cannot be used as a decorator. Did you mean to call it first? } \ No newline at end of file From 86315ed4119db22cc900b58d053f471d4d354119 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 29 Sep 2017 22:01:00 -0700 Subject: [PATCH 05/10] Added test and adjusted reporting logic. --- src/compiler/checker.ts | 3 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 0 .../compiler/potentiallyUncalledDecorators.ts | 74 +++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) mode change 100755 => 100644 src/compiler/emitter.ts create mode 100644 tests/cases/compiler/potentiallyUncalledDecorators.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a272ac15e72e6..23da94437aeaa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16382,7 +16382,7 @@ namespace ts { } if (isPotentiallyUncalledDecorator(node, callSignatures)) { - error(node, Diagnostics.This_function_cannot_be_used_as_a_decorator_Did_you_mean_to_call_it_first); + error(node, Diagnostics.This_value_has_type_0_which_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first, typeToString(funcType)); return resolveErrorCall(node); } @@ -16406,6 +16406,7 @@ namespace ts { function isPotentiallyUncalledDecorator(decorator: Decorator, signatures: Signature[]) { return signatures.length && every(signatures, signature => signature.minArgumentCount === 0 && + !signature.hasRestParameter && signature.parameters.length < getEffectiveArgumentCount(decorator, /*args*/ undefined, signature)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 722985aac78c1..57dc9f28834f0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -907,7 +907,7 @@ "category": "Error", "code": 1328 }, - "This function cannot be used as a decorator. Did you mean to call it first?": { + "This value has type '{0}' which accepts too few arguments to be used as a decorator here. Did you mean to call it first?": { "category": "Error", "code": 1329 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts old mode 100755 new mode 100644 diff --git a/tests/cases/compiler/potentiallyUncalledDecorators.ts b/tests/cases/compiler/potentiallyUncalledDecorators.ts new file mode 100644 index 0000000000000..3c92a21eff0c4 --- /dev/null +++ b/tests/cases/compiler/potentiallyUncalledDecorators.ts @@ -0,0 +1,74 @@ +// @target: esnext +// @module: esnext +// @experimentalDecorators: true + +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +class FooComponent { + @Input foo: string; +} + +// 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; + +@noArgs +class A { + @noArgs foo: any; + @noArgs bar() { } +} + +@allRest +class B { + @allRest foo: any; + @allRest bar() { } +} + +@oneOptional +class C { + @oneOptional foo: any; + @oneOptional bar() { } +} + +@twoOptional +class D { + @twoOptional foo: any; + @twoOptional bar() { } +} + +@threeOptional +class E { + @threeOptional foo: any; + @threeOptional bar() { } +} + +@oneOptionalWithRest +class F { + @oneOptionalWithRest foo: any; + @oneOptionalWithRest bar() { } +} + +export { }; From 803b5660fcf6b8d50b0751d76629de18c79540a3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 29 Sep 2017 22:02:35 -0700 Subject: [PATCH 06/10] Accepted baselines. --- .../decoratorOnClassMethod6.errors.txt | 4 +- .../decoratorOnClassProperty11.errors.txt | 4 +- .../potentiallyUncalledDecorators.errors.txt | 167 ++++++++++++++++ .../potentiallyUncalledDecorators.js | 170 ++++++++++++++++ .../potentiallyUncalledDecorators.symbols | 182 +++++++++++++++++ .../potentiallyUncalledDecorators.types | 188 ++++++++++++++++++ 6 files changed, 711 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/potentiallyUncalledDecorators.errors.txt create mode 100644 tests/baselines/reference/potentiallyUncalledDecorators.js create mode 100644 tests/baselines/reference/potentiallyUncalledDecorators.symbols create mode 100644 tests/baselines/reference/potentiallyUncalledDecorators.types diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt index befe582025c86..7a9e5fea35563 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: This function cannot be used as a decorator. Did you mean to call it first? +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: This value has type '() => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): class C { @dec ["method"]() {} ~~~~ -!!! error TS1329: This function cannot be used as a decorator. Did you mean to call it first? +!!! error TS1329: This value has type '() => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt index 771ca46b572d4..9d16d64df4104 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: This function cannot be used as a decorator. Did you mean to call it first? +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: This value has type '() => (target: any, propertyKey: string) => void' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts( class C { @dec prop; ~~~~ -!!! error TS1329: This function cannot be used as a decorator. Did you mean to call it first? +!!! error TS1329: This value has type '() => (target: any, propertyKey: string) => void' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? } \ No newline at end of file diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt new file mode 100644 index 0000000000000..e2858160ba95c --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt @@ -0,0 +1,167 @@ +tests/cases/compiler/potentiallyUncalledDecorators.ts(4,5): error TS1329: This value has type '(bindingPropertyName?: string) => any' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(34,1): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(36,5): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(37,5): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(40,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(42,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(43,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(46,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(48,5): error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(49,5): error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/compiler/potentiallyUncalledDecorators.ts(52,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(54,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(55,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(58,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(60,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(61,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(64,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(66,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(67,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: This value has type '(bindingPropertyName?: string) => any' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + } + + // 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; + + @noArgs + ~~~~~~~ +!!! error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + class A { + @noArgs foo: any; + ~~~~~~~ +!!! error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + @noArgs bar() { } + ~~~~~~~ +!!! error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + } + + @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: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + @oneOptional bar() { } + ~~~~~~~~~~~~ +!!! error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? + } + + @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>'. + } + + export { }; + \ No newline at end of file diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.js b/tests/baselines/reference/potentiallyUncalledDecorators.js new file mode 100644 index 0000000000000..a0dcc80ea0edf --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.js @@ -0,0 +1,170 @@ +//// [potentiallyUncalledDecorators.ts] +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +class FooComponent { + @Input foo: string; +} + +// 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; + +@noArgs +class A { + @noArgs foo: any; + @noArgs bar() { } +} + +@allRest +class B { + @allRest foo: any; + @allRest bar() { } +} + +@oneOptional +class C { + @oneOptional foo: any; + @oneOptional bar() { } +} + +@twoOptional +class D { + @twoOptional foo: any; + @twoOptional bar() { } +} + +@threeOptional +class E { + @threeOptional foo: any; + @threeOptional bar() { } +} + +@oneOptionalWithRest +class F { + @oneOptionalWithRest foo: any; + @oneOptionalWithRest bar() { } +} + +export { }; + + +//// [potentiallyUncalledDecorators.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +class FooComponent { +} +__decorate([ + Input +], FooComponent.prototype, "foo", void 0); +class Person { +} +__decorate([ + tracked +], Person.prototype, "person", void 0); +class MultiplyByTwo { + get multiplied() { + return this.args.number * 2; + } +} +__decorate([ + tracked('args') +], MultiplyByTwo.prototype, "multiplied", null); +let A = class A { + bar() { } +}; +__decorate([ + noArgs +], A.prototype, "foo", void 0); +__decorate([ + noArgs +], A.prototype, "bar", null); +A = __decorate([ + noArgs +], A); +let B = class B { + bar() { } +}; +__decorate([ + allRest +], B.prototype, "foo", void 0); +__decorate([ + allRest +], B.prototype, "bar", null); +B = __decorate([ + allRest +], B); +let C = class C { + bar() { } +}; +__decorate([ + oneOptional +], C.prototype, "foo", void 0); +__decorate([ + oneOptional +], C.prototype, "bar", null); +C = __decorate([ + oneOptional +], C); +let D = class D { + bar() { } +}; +__decorate([ + twoOptional +], D.prototype, "foo", void 0); +__decorate([ + twoOptional +], D.prototype, "bar", null); +D = __decorate([ + twoOptional +], D); +let E = class E { + bar() { } +}; +__decorate([ + threeOptional +], E.prototype, "foo", void 0); +__decorate([ + threeOptional +], E.prototype, "bar", null); +E = __decorate([ + threeOptional +], E); +let F = class F { + bar() { } +}; +__decorate([ + oneOptionalWithRest +], F.prototype, "foo", void 0); +__decorate([ + oneOptionalWithRest +], F.prototype, "bar", null); +F = __decorate([ + oneOptionalWithRest +], F); diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.symbols b/tests/baselines/reference/potentiallyUncalledDecorators.symbols new file mode 100644 index 0000000000000..ff7cc253a27df --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.symbols @@ -0,0 +1,182 @@ +=== tests/cases/compiler/potentiallyUncalledDecorators.ts === +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +>Input : Symbol(Input, Decl(potentiallyUncalledDecorators.ts, 0, 0)) +>bindingPropertyName : Symbol(bindingPropertyName, Decl(potentiallyUncalledDecorators.ts, 1, 23)) + +class FooComponent { +>FooComponent : Symbol(FooComponent, Decl(potentiallyUncalledDecorators.ts, 1, 58)) + + @Input foo: string; +>Input : Symbol(Input, Decl(potentiallyUncalledDecorators.ts, 0, 0)) +>foo : Symbol(FooComponent.foo, Decl(potentiallyUncalledDecorators.ts, 2, 20)) +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) +>PropertyDecorator : Symbol(PropertyDecorator, Decl(lib.es5.d.ts, --, --)) +>watchedProperties : Symbol(watchedProperties, Decl(potentiallyUncalledDecorators.ts, 7, 46)) + +class Person { +>Person : Symbol(Person, Decl(potentiallyUncalledDecorators.ts, 7, 85)) + + @tracked person; any; +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) +>person : Symbol(Person.person, Decl(potentiallyUncalledDecorators.ts, 9, 14)) +>any : Symbol(Person.any, Decl(potentiallyUncalledDecorators.ts, 10, 20)) +} + +class MultiplyByTwo { +>MultiplyByTwo : Symbol(MultiplyByTwo, Decl(potentiallyUncalledDecorators.ts, 11, 1)) + + args: any; +>args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) + + @tracked('args') +>tracked : Symbol(tracked, Decl(potentiallyUncalledDecorators.ts, 7, 13)) + + get multiplied() { +>multiplied : Symbol(MultiplyByTwo.multiplied, Decl(potentiallyUncalledDecorators.ts, 14, 14)) + + return this.args.number * 2; +>this.args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) +>this : Symbol(MultiplyByTwo, Decl(potentiallyUncalledDecorators.ts, 11, 1)) +>args : Symbol(MultiplyByTwo.args, Decl(potentiallyUncalledDecorators.ts, 13, 21)) + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) +>MethodDecorator : Symbol(MethodDecorator, Decl(lib.es5.d.ts, --, --)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.es5.d.ts, --, --)) +>PropertyDecorator : Symbol(PropertyDecorator, Decl(lib.es5.d.ts, --, --)) +} + +declare function noArgs(): OmniDecorator; +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function allRest(...args: any[]): OmniDecorator; +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>args : Symbol(args, Decl(potentiallyUncalledDecorators.ts, 27, 25)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function oneOptional(x?: any): OmniDecorator; +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 28, 29)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function twoOptional(x?: any, y?: any): OmniDecorator; +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 29, 29)) +>y : Symbol(y, Decl(potentiallyUncalledDecorators.ts, 29, 37)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 30, 31)) +>y : Symbol(y, Decl(potentiallyUncalledDecorators.ts, 30, 39)) +>z : Symbol(z, Decl(potentiallyUncalledDecorators.ts, 30, 48)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>x : Symbol(x, Decl(potentiallyUncalledDecorators.ts, 31, 37)) +>args : Symbol(args, Decl(potentiallyUncalledDecorators.ts, 31, 45)) +>OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) + +@noArgs +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) + +class A { +>A : Symbol(A, Decl(potentiallyUncalledDecorators.ts, 31, 77)) + + @noArgs foo: any; +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>foo : Symbol(A.foo, Decl(potentiallyUncalledDecorators.ts, 34, 9)) + + @noArgs bar() { } +>noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) +>bar : Symbol(A.bar, Decl(potentiallyUncalledDecorators.ts, 35, 21)) +} + +@allRest +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) + +class B { +>B : Symbol(B, Decl(potentiallyUncalledDecorators.ts, 37, 1)) + + @allRest foo: any; +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>foo : Symbol(B.foo, Decl(potentiallyUncalledDecorators.ts, 40, 9)) + + @allRest bar() { } +>allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) +>bar : Symbol(B.bar, Decl(potentiallyUncalledDecorators.ts, 41, 22)) +} + +@oneOptional +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) + +class C { +>C : Symbol(C, Decl(potentiallyUncalledDecorators.ts, 43, 1)) + + @oneOptional foo: any; +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>foo : Symbol(C.foo, Decl(potentiallyUncalledDecorators.ts, 46, 9)) + + @oneOptional bar() { } +>oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) +>bar : Symbol(C.bar, Decl(potentiallyUncalledDecorators.ts, 47, 26)) +} + +@twoOptional +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) + +class D { +>D : Symbol(D, Decl(potentiallyUncalledDecorators.ts, 49, 1)) + + @twoOptional foo: any; +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>foo : Symbol(D.foo, Decl(potentiallyUncalledDecorators.ts, 52, 9)) + + @twoOptional bar() { } +>twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) +>bar : Symbol(D.bar, Decl(potentiallyUncalledDecorators.ts, 53, 26)) +} + +@threeOptional +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) + +class E { +>E : Symbol(E, Decl(potentiallyUncalledDecorators.ts, 55, 1)) + + @threeOptional foo: any; +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>foo : Symbol(E.foo, Decl(potentiallyUncalledDecorators.ts, 58, 9)) + + @threeOptional bar() { } +>threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) +>bar : Symbol(E.bar, Decl(potentiallyUncalledDecorators.ts, 59, 28)) +} + +@oneOptionalWithRest +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) + +class F { +>F : Symbol(F, Decl(potentiallyUncalledDecorators.ts, 61, 1)) + + @oneOptionalWithRest foo: any; +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>foo : Symbol(F.foo, Decl(potentiallyUncalledDecorators.ts, 64, 9)) + + @oneOptionalWithRest bar() { } +>oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) +>bar : Symbol(F.bar, Decl(potentiallyUncalledDecorators.ts, 65, 34)) +} + +export { }; + diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.types b/tests/baselines/reference/potentiallyUncalledDecorators.types new file mode 100644 index 0000000000000..d79972659d3e5 --- /dev/null +++ b/tests/baselines/reference/potentiallyUncalledDecorators.types @@ -0,0 +1,188 @@ +=== tests/cases/compiler/potentiallyUncalledDecorators.ts === +// Angular-style Input/Output API: +declare function Input(bindingPropertyName?: string): any; +>Input : (bindingPropertyName?: string) => any +>bindingPropertyName : string + +class FooComponent { +>FooComponent : FooComponent + + @Input foo: string; +>Input : (bindingPropertyName?: string) => any +>foo : string +} + +// Glimmer-style tracked API: +declare const tracked: PropertyDecorator & { (...watchedProperties: string[]): any; } +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>PropertyDecorator : PropertyDecorator +>watchedProperties : string[] + +class Person { +>Person : Person + + @tracked person; any; +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>person : any +>any : any +} + +class MultiplyByTwo { +>MultiplyByTwo : MultiplyByTwo + + args: any; +>args : any + + @tracked('args') +>tracked('args') : any +>tracked : PropertyDecorator & ((...watchedProperties: string[]) => any) +>'args' : "args" + + get multiplied() { +>multiplied : number + + return this.args.number * 2; +>this.args.number * 2 : number +>this.args.number : any +>this.args : any +>this : this +>args : any +>number : any +>2 : 2 + } +} + +// Other fun stuff. + +interface OmniDecorator extends MethodDecorator, ClassDecorator, PropertyDecorator { +>OmniDecorator : OmniDecorator +>MethodDecorator : MethodDecorator +>ClassDecorator : ClassDecorator +>PropertyDecorator : PropertyDecorator +} + +declare function noArgs(): OmniDecorator; +>noArgs : () => OmniDecorator +>OmniDecorator : OmniDecorator + +declare function allRest(...args: any[]): OmniDecorator; +>allRest : (...args: any[]) => OmniDecorator +>args : any[] +>OmniDecorator : OmniDecorator + +declare function oneOptional(x?: any): OmniDecorator; +>oneOptional : (x?: any) => OmniDecorator +>x : any +>OmniDecorator : OmniDecorator + +declare function twoOptional(x?: any, y?: any): OmniDecorator; +>twoOptional : (x?: any, y?: any) => OmniDecorator +>x : any +>y : any +>OmniDecorator : OmniDecorator + +declare function threeOptional(x?: any, y?: any, z?: any): OmniDecorator; +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>x : any +>y : any +>z : any +>OmniDecorator : OmniDecorator + +declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>x : any +>args : any[] +>OmniDecorator : OmniDecorator + +@noArgs +>noArgs : () => OmniDecorator + +class A { +>A : A + + @noArgs foo: any; +>noArgs : () => OmniDecorator +>foo : any + + @noArgs bar() { } +>noArgs : () => OmniDecorator +>bar : () => void +} + +@allRest +>allRest : (...args: any[]) => OmniDecorator + +class B { +>B : B + + @allRest foo: any; +>allRest : (...args: any[]) => OmniDecorator +>foo : any + + @allRest bar() { } +>allRest : (...args: any[]) => OmniDecorator +>bar : () => void +} + +@oneOptional +>oneOptional : (x?: any) => OmniDecorator + +class C { +>C : C + + @oneOptional foo: any; +>oneOptional : (x?: any) => OmniDecorator +>foo : any + + @oneOptional bar() { } +>oneOptional : (x?: any) => OmniDecorator +>bar : () => void +} + +@twoOptional +>twoOptional : (x?: any, y?: any) => OmniDecorator + +class D { +>D : D + + @twoOptional foo: any; +>twoOptional : (x?: any, y?: any) => OmniDecorator +>foo : any + + @twoOptional bar() { } +>twoOptional : (x?: any, y?: any) => OmniDecorator +>bar : () => void +} + +@threeOptional +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator + +class E { +>E : E + + @threeOptional foo: any; +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>foo : any + + @threeOptional bar() { } +>threeOptional : (x?: any, y?: any, z?: any) => OmniDecorator +>bar : () => void +} + +@oneOptionalWithRest +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator + +class F { +>F : F + + @oneOptionalWithRest foo: any; +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>foo : any + + @oneOptionalWithRest bar() { } +>oneOptionalWithRest : (x?: any, ...args: any[]) => OmniDecorator +>bar : () => void +} + +export { }; + From 96bb796730cc281a4850bfa43cffcc7929d98c6b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 2 Oct 2017 17:56:10 -0700 Subject: [PATCH 07/10] Improve error message for uncalled decorators. --- src/compiler/checker.ts | 4 +++- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23da94437aeaa..c9d6c6949a962 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16382,7 +16382,9 @@ namespace ts { } if (isPotentiallyUncalledDecorator(node, callSignatures)) { - error(node, Diagnostics.This_value_has_type_0_which_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first, typeToString(funcType)); + const printer = createPrinter({ removeComments: true }); + const nodeStr = printer.printNode(EmitHint.Expression, node.expression, getSourceFileOfNode(node)); + error(node, Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0, nodeStr); return resolveErrorCall(node); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 57dc9f28834f0..eb508857e6f2e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -907,7 +907,7 @@ "category": "Error", "code": 1328 }, - "This value has type '{0}' which accepts too few arguments to be used as a decorator here. Did you mean to call it first?": { + "'{0}' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@{0}()'?": { "category": "Error", "code": 1329 }, From 392cd6117bb5c8941141e18919f051f66bf0dd5c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 2 Oct 2017 18:00:00 -0700 Subject: [PATCH 08/10] Added a test for an 'any'-type decorator. --- tests/cases/compiler/potentiallyUncalledDecorators.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/cases/compiler/potentiallyUncalledDecorators.ts b/tests/cases/compiler/potentiallyUncalledDecorators.ts index 3c92a21eff0c4..6e537686d0f56 100644 --- a/tests/cases/compiler/potentiallyUncalledDecorators.ts +++ b/tests/cases/compiler/potentiallyUncalledDecorators.ts @@ -34,6 +34,7 @@ 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 class A { @@ -71,4 +72,10 @@ class F { @oneOptionalWithRest bar() { } } +@anyDec +class G { + @anyDec foo: any; + @anyDec bar() { } +} + export { }; From 35cfcff0d4d0861ec27049eb32fc56075ca0642c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 2 Oct 2017 18:09:28 -0700 Subject: [PATCH 09/10] Use 'getTextOfNode'. --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c9d6c6949a962..8d8595409e83d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16382,8 +16382,7 @@ namespace ts { } if (isPotentiallyUncalledDecorator(node, callSignatures)) { - const printer = createPrinter({ removeComments: true }); - const nodeStr = printer.printNode(EmitHint.Expression, node.expression, getSourceFileOfNode(node)); + const nodeStr = getTextOfNode(node.expression, /*includeTrivia*/ false); error(node, Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0, nodeStr); return resolveErrorCall(node); } From 7750a88957fec5c41fb286b8d59dfb4487a1b63c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 2 Oct 2017 18:50:05 -0700 Subject: [PATCH 10/10] Accepted baselines. --- .../decoratorOnClassMethod6.errors.txt | 4 +- .../decoratorOnClassProperty11.errors.txt | 4 +- .../potentiallyUncalledDecorators.errors.txt | 57 +++++++++++-------- .../potentiallyUncalledDecorators.js | 19 +++++++ .../potentiallyUncalledDecorators.symbols | 54 ++++++++++++------ .../potentiallyUncalledDecorators.types | 18 ++++++ 6 files changed, 109 insertions(+), 47 deletions(-) diff --git a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt index 7a9e5fea35563..b863a9db72c9c 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: This value has type '() => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? ==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): class C { @dec ["method"]() {} ~~~~ -!!! error TS1329: This value has type '() => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt index 9d16d64df4104..537daaf44ea6a 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: This value has type '() => (target: any, propertyKey: string) => void' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? ==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts( class C { @dec prop; ~~~~ -!!! error TS1329: This value has type '() => (target: any, propertyKey: string) => void' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! error TS1329: 'dec' accepts too few arguments to be used as a decorator here. Did you mean to call it first and write '@dec()'? } \ No newline at end of file diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt index e2858160ba95c..9028ebe0377eb 100644 --- a/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt +++ b/tests/baselines/reference/potentiallyUncalledDecorators.errors.txt @@ -1,39 +1,39 @@ -tests/cases/compiler/potentiallyUncalledDecorators.ts(4,5): error TS1329: This value has type '(bindingPropertyName?: string) => any' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(34,1): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(36,5): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(37,5): error TS1329: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(40,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. +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(42,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +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(43,5): error TS1241: Unable to resolve signature of method 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(46,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. +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(48,5): error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(49,5): error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? -tests/cases/compiler/potentiallyUncalledDecorators.ts(52,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. +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(54,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +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(55,5): error TS1241: Unable to resolve signature of method 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(58,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. +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(60,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +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(61,5): error TS1241: Unable to resolve signature of method 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(64,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. +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(66,5): error TS1236: The return type of a property decorator function must be either 'void' or 'any'. +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(67,5): error TS1241: Unable to resolve signature of method 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>'. @@ -43,7 +43,7 @@ tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1241: Unabl class FooComponent { @Input foo: string; ~~~~~~ -!!! error TS1329: This value has type '(bindingPropertyName?: string) => any' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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: @@ -72,17 +72,18 @@ tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1241: Unabl 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: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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: This value has type '() => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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 @@ -109,10 +110,10 @@ tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1241: Unabl class C { @oneOptional foo: any; ~~~~~~~~~~~~ -!!! error TS1329: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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: This value has type '(x?: any) => OmniDecorator' which accepts too few arguments to be used as a decorator here. Did you mean to call it first? +!!! 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 @@ -163,5 +164,11 @@ tests/cases/compiler/potentiallyUncalledDecorators.ts(67,5): error TS1241: Unabl !!! error TS1241: Type 'OmniDecorator' has no properties in common with type 'TypedPropertyDescriptor<() => void>'. } + @anyDec + class G { + @anyDec foo: any; + @anyDec bar() { } + } + export { }; \ No newline at end of file diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.js b/tests/baselines/reference/potentiallyUncalledDecorators.js index a0dcc80ea0edf..b69f848a8c933 100644 --- a/tests/baselines/reference/potentiallyUncalledDecorators.js +++ b/tests/baselines/reference/potentiallyUncalledDecorators.js @@ -31,6 +31,7 @@ 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 class A { @@ -68,6 +69,12 @@ class F { @oneOptionalWithRest bar() { } } +@anyDec +class G { + @anyDec foo: any; + @anyDec bar() { } +} + export { }; @@ -168,3 +175,15 @@ __decorate([ F = __decorate([ oneOptionalWithRest ], F); +let G = class G { + bar() { } +}; +__decorate([ + anyDec +], G.prototype, "foo", void 0); +__decorate([ + anyDec +], G.prototype, "bar", null); +G = __decorate([ + anyDec +], G); diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.symbols b/tests/baselines/reference/potentiallyUncalledDecorators.symbols index ff7cc253a27df..38fe3f3dc520e 100644 --- a/tests/baselines/reference/potentiallyUncalledDecorators.symbols +++ b/tests/baselines/reference/potentiallyUncalledDecorators.symbols @@ -88,94 +88,112 @@ declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; >args : Symbol(args, Decl(potentiallyUncalledDecorators.ts, 31, 45)) >OmniDecorator : Symbol(OmniDecorator, Decl(potentiallyUncalledDecorators.ts, 19, 1)) +declare const anyDec: any; +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) + @noArgs >noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) class A { ->A : Symbol(A, Decl(potentiallyUncalledDecorators.ts, 31, 77)) +>A : Symbol(A, Decl(potentiallyUncalledDecorators.ts, 32, 26)) @noArgs foo: any; >noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) ->foo : Symbol(A.foo, Decl(potentiallyUncalledDecorators.ts, 34, 9)) +>foo : Symbol(A.foo, Decl(potentiallyUncalledDecorators.ts, 35, 9)) @noArgs bar() { } >noArgs : Symbol(noArgs, Decl(potentiallyUncalledDecorators.ts, 24, 1)) ->bar : Symbol(A.bar, Decl(potentiallyUncalledDecorators.ts, 35, 21)) +>bar : Symbol(A.bar, Decl(potentiallyUncalledDecorators.ts, 36, 21)) } @allRest >allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) class B { ->B : Symbol(B, Decl(potentiallyUncalledDecorators.ts, 37, 1)) +>B : Symbol(B, Decl(potentiallyUncalledDecorators.ts, 38, 1)) @allRest foo: any; >allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) ->foo : Symbol(B.foo, Decl(potentiallyUncalledDecorators.ts, 40, 9)) +>foo : Symbol(B.foo, Decl(potentiallyUncalledDecorators.ts, 41, 9)) @allRest bar() { } >allRest : Symbol(allRest, Decl(potentiallyUncalledDecorators.ts, 26, 41)) ->bar : Symbol(B.bar, Decl(potentiallyUncalledDecorators.ts, 41, 22)) +>bar : Symbol(B.bar, Decl(potentiallyUncalledDecorators.ts, 42, 22)) } @oneOptional >oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) class C { ->C : Symbol(C, Decl(potentiallyUncalledDecorators.ts, 43, 1)) +>C : Symbol(C, Decl(potentiallyUncalledDecorators.ts, 44, 1)) @oneOptional foo: any; >oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) ->foo : Symbol(C.foo, Decl(potentiallyUncalledDecorators.ts, 46, 9)) +>foo : Symbol(C.foo, Decl(potentiallyUncalledDecorators.ts, 47, 9)) @oneOptional bar() { } >oneOptional : Symbol(oneOptional, Decl(potentiallyUncalledDecorators.ts, 27, 56)) ->bar : Symbol(C.bar, Decl(potentiallyUncalledDecorators.ts, 47, 26)) +>bar : Symbol(C.bar, Decl(potentiallyUncalledDecorators.ts, 48, 26)) } @twoOptional >twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) class D { ->D : Symbol(D, Decl(potentiallyUncalledDecorators.ts, 49, 1)) +>D : Symbol(D, Decl(potentiallyUncalledDecorators.ts, 50, 1)) @twoOptional foo: any; >twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) ->foo : Symbol(D.foo, Decl(potentiallyUncalledDecorators.ts, 52, 9)) +>foo : Symbol(D.foo, Decl(potentiallyUncalledDecorators.ts, 53, 9)) @twoOptional bar() { } >twoOptional : Symbol(twoOptional, Decl(potentiallyUncalledDecorators.ts, 28, 53)) ->bar : Symbol(D.bar, Decl(potentiallyUncalledDecorators.ts, 53, 26)) +>bar : Symbol(D.bar, Decl(potentiallyUncalledDecorators.ts, 54, 26)) } @threeOptional >threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) class E { ->E : Symbol(E, Decl(potentiallyUncalledDecorators.ts, 55, 1)) +>E : Symbol(E, Decl(potentiallyUncalledDecorators.ts, 56, 1)) @threeOptional foo: any; >threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) ->foo : Symbol(E.foo, Decl(potentiallyUncalledDecorators.ts, 58, 9)) +>foo : Symbol(E.foo, Decl(potentiallyUncalledDecorators.ts, 59, 9)) @threeOptional bar() { } >threeOptional : Symbol(threeOptional, Decl(potentiallyUncalledDecorators.ts, 29, 62)) ->bar : Symbol(E.bar, Decl(potentiallyUncalledDecorators.ts, 59, 28)) +>bar : Symbol(E.bar, Decl(potentiallyUncalledDecorators.ts, 60, 28)) } @oneOptionalWithRest >oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) class F { ->F : Symbol(F, Decl(potentiallyUncalledDecorators.ts, 61, 1)) +>F : Symbol(F, Decl(potentiallyUncalledDecorators.ts, 62, 1)) @oneOptionalWithRest foo: any; >oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) ->foo : Symbol(F.foo, Decl(potentiallyUncalledDecorators.ts, 64, 9)) +>foo : Symbol(F.foo, Decl(potentiallyUncalledDecorators.ts, 65, 9)) @oneOptionalWithRest bar() { } >oneOptionalWithRest : Symbol(oneOptionalWithRest, Decl(potentiallyUncalledDecorators.ts, 30, 73)) ->bar : Symbol(F.bar, Decl(potentiallyUncalledDecorators.ts, 65, 34)) +>bar : Symbol(F.bar, Decl(potentiallyUncalledDecorators.ts, 66, 34)) +} + +@anyDec +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) + +class G { +>G : Symbol(G, Decl(potentiallyUncalledDecorators.ts, 68, 1)) + + @anyDec foo: any; +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) +>foo : Symbol(G.foo, Decl(potentiallyUncalledDecorators.ts, 71, 9)) + + @anyDec bar() { } +>anyDec : Symbol(anyDec, Decl(potentiallyUncalledDecorators.ts, 32, 13)) +>bar : Symbol(G.bar, Decl(potentiallyUncalledDecorators.ts, 72, 21)) } export { }; diff --git a/tests/baselines/reference/potentiallyUncalledDecorators.types b/tests/baselines/reference/potentiallyUncalledDecorators.types index d79972659d3e5..cad861fc7b417 100644 --- a/tests/baselines/reference/potentiallyUncalledDecorators.types +++ b/tests/baselines/reference/potentiallyUncalledDecorators.types @@ -94,6 +94,9 @@ declare function oneOptionalWithRest(x?: any, ...args: any[]): OmniDecorator; >args : any[] >OmniDecorator : OmniDecorator +declare const anyDec: any; +>anyDec : any + @noArgs >noArgs : () => OmniDecorator @@ -184,5 +187,20 @@ class F { >bar : () => void } +@anyDec +>anyDec : any + +class G { +>G : G + + @anyDec foo: any; +>anyDec : any +>foo : any + + @anyDec bar() { } +>anyDec : any +>bar : () => void +} + export { };