mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-12 01:48:33 -05:00
Merge pull request #5235 from Microsoft/fixDecoratorDiagostics
Fix exception in compiler when type checking decorators with generics.
This commit is contained in:
@@ -437,8 +437,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain {
|
||||
Debug.assert(!headChain.next);
|
||||
headChain.next = tailChain;
|
||||
let lastChain = headChain;
|
||||
while (lastChain.next) {
|
||||
lastChain = lastChain.next;
|
||||
}
|
||||
|
||||
lastChain.next = tailChain;
|
||||
return headChain;
|
||||
}
|
||||
|
||||
|
||||
22
tests/baselines/reference/decoratorCallGeneric.errors.txt
Normal file
22
tests/baselines/reference/decoratorCallGeneric.errors.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
tests/cases/conformance/decorators/decoratorCallGeneric.ts(7,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
|
||||
The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/decorators/decoratorCallGeneric.ts (1 errors) ====
|
||||
interface I<T> {
|
||||
prototype: T,
|
||||
m: () => T
|
||||
}
|
||||
function dec<T>(c: I<T>) { }
|
||||
|
||||
@dec
|
||||
~~~
|
||||
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
|
||||
!!! error TS1238: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
!!! error TS1238: Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
|
||||
class C {
|
||||
_brand: any;
|
||||
static m() {}
|
||||
}
|
||||
|
||||
31
tests/baselines/reference/decoratorCallGeneric.js
Normal file
31
tests/baselines/reference/decoratorCallGeneric.js
Normal file
@@ -0,0 +1,31 @@
|
||||
//// [decoratorCallGeneric.ts]
|
||||
interface I<T> {
|
||||
prototype: T,
|
||||
m: () => T
|
||||
}
|
||||
function dec<T>(c: I<T>) { }
|
||||
|
||||
@dec
|
||||
class C {
|
||||
_brand: any;
|
||||
static m() {}
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorCallGeneric.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;
|
||||
};
|
||||
function dec(c) { }
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.m = function () { };
|
||||
C = __decorate([
|
||||
dec
|
||||
], C);
|
||||
return C;
|
||||
})();
|
||||
12
tests/cases/conformance/decorators/decoratorCallGeneric.ts
Normal file
12
tests/cases/conformance/decorators/decoratorCallGeneric.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// @experimentalDecorators: true
|
||||
interface I<T> {
|
||||
prototype: T,
|
||||
m: () => T
|
||||
}
|
||||
function dec<T>(c: I<T>) { }
|
||||
|
||||
@dec
|
||||
class C {
|
||||
_brand: any;
|
||||
static m() {}
|
||||
}
|
||||
Reference in New Issue
Block a user