mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge pull request #18811 from Microsoft/uncalledDecorator
Give a more helpful error message for certain decorators with too many arguments
This commit is contained in:
81
tests/cases/compiler/potentiallyUncalledDecorators.ts
Normal file
81
tests/cases/compiler/potentiallyUncalledDecorators.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
// @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;
|
||||
declare const anyDec: any;
|
||||
|
||||
@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() { }
|
||||
}
|
||||
|
||||
@anyDec
|
||||
class G {
|
||||
@anyDec foo: any;
|
||||
@anyDec bar() { }
|
||||
}
|
||||
|
||||
export { };
|
||||
Reference in New Issue
Block a user