Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28609 from ajafff/class-decorator-generics
resolve TypeReference in class decorator at parent of class
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//// [decoratorReferences.ts] | ||
declare function y(...args: any[]): any; | ||
type T = number; | ||
@y(1 as T, C) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class | ||
class C<T> { | ||
@y(null as T) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class | ||
method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. | ||
} | ||
|
||
//// [decoratorReferences.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; | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
C_1 = C; | ||
C.prototype.method = function (x, y) { }; // <-- decorator y should be resolved at the class declaration, not the parameter. | ||
var C_1; | ||
__decorate([ | ||
y(null) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class | ||
, | ||
__param(0, y) | ||
], C.prototype, "method"); | ||
C = C_1 = __decorate([ | ||
y(1, C_1) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class | ||
], C); | ||
return C; | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
=== tests/cases/compiler/decoratorReferences.ts === | ||
declare function y(...args: any[]): any; | ||
>y : Symbol(y, Decl(decoratorReferences.ts, 0, 0)) | ||
>args : Symbol(args, Decl(decoratorReferences.ts, 0, 19)) | ||
|
||
type T = number; | ||
>T : Symbol(T, Decl(decoratorReferences.ts, 0, 40)) | ||
|
||
@y(1 as T, C) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class | ||
>y : Symbol(y, Decl(decoratorReferences.ts, 0, 0)) | ||
>T : Symbol(T, Decl(decoratorReferences.ts, 0, 40)) | ||
>C : Symbol(C, Decl(decoratorReferences.ts, 1, 16)) | ||
|
||
class C<T> { | ||
>C : Symbol(C, Decl(decoratorReferences.ts, 1, 16)) | ||
>T : Symbol(T, Decl(decoratorReferences.ts, 3, 8)) | ||
|
||
@y(null as T) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class | ||
>y : Symbol(y, Decl(decoratorReferences.ts, 0, 0)) | ||
>T : Symbol(T, Decl(decoratorReferences.ts, 3, 8)) | ||
|
||
method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. | ||
>method : Symbol(C.method, Decl(decoratorReferences.ts, 3, 12)) | ||
>y : Symbol(y, Decl(decoratorReferences.ts, 0, 0)) | ||
>x : Symbol(x, Decl(decoratorReferences.ts, 5, 11)) | ||
>y : Symbol(y, Decl(decoratorReferences.ts, 5, 16)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
=== tests/cases/compiler/decoratorReferences.ts === | ||
declare function y(...args: any[]): any; | ||
>y : (...args: any[]) => any | ||
>args : any[] | ||
|
||
type T = number; | ||
>T : number | ||
|
||
@y(1 as T, C) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class | ||
>y(1 as T, C) : any | ||
>y : (...args: any[]) => any | ||
>1 as T : number | ||
>1 : 1 | ||
>C : typeof C | ||
|
||
class C<T> { | ||
>C : C<T> | ||
|
||
@y(null as T) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class | ||
>y(null as T) : any | ||
>y : (...args: any[]) => any | ||
>null as T : T | ||
>null : null | ||
|
||
method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. | ||
>method : (x: any, y: any) => void | ||
>y : (...args: any[]) => any | ||
>x : any | ||
>y : any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @experimentalDecorators: true | ||
|
||
declare function y(...args: any[]): any; | ||
type T = number; | ||
@y(1 as T, C) // <-- T should be resolved to the type alias, not the type parameter of the class; C should resolve to the class | ||
class C<T> { | ||
@y(null as T) // <-- y should resolve to the function declaration, not the parameter; T should resolve to the type parameter of the class | ||
method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. | ||
} |