mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Added test and adjusted reporting logic.
This commit is contained in:
parent
08ef6e4bea
commit
86315ed411
@ -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));
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
},
|
||||
|
||||
0
src/compiler/emitter.ts
Executable file → Normal file
0
src/compiler/emitter.ts
Executable file → Normal file
74
tests/cases/compiler/potentiallyUncalledDecorators.ts
Normal file
74
tests/cases/compiler/potentiallyUncalledDecorators.ts
Normal file
@ -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 { };
|
||||
Loading…
x
Reference in New Issue
Block a user