Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="moduleNameResolver.ts"/>
/// <reference path="moduleNameResolver.ts"/>
/// <reference path="binder.ts"/>

/* @internal */
Expand Down Expand Up @@ -3986,16 +3986,13 @@ namespace ts {
function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
const typeArgCount = length(typeArgumentNodes);
return filter(getSignaturesOfType(type, SignatureKind.Construct),
sig => typeArgCount >= getMinTypeArgumentCount(sig.typeParameters) && typeArgCount <= length(sig.typeParameters));
sig => typeArgCount <= length(sig.typeParameters));
}

function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
let signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
if (typeArgumentNodes) {
const typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
signatures = map(signatures, sig => getSignatureInstantiation(sig, typeArguments));
}
return signatures;
const typeArguments = length(typeArgumentNodes) ? map(typeArgumentNodes, getTypeFromTypeNode): undefined
return signatures && map(signatures, sig => length(sig.typeParameters) ? getSignatureInstantiation(sig, typeArguments) : sig);
}

/**
Expand Down Expand Up @@ -4587,9 +4584,8 @@ namespace ts {
const typeArgCount = length(typeArguments);
const result: Signature[] = [];
for (const baseSig of baseSignatures) {
const minTypeArgumentCount = getMinTypeArgumentCount(baseSig.typeParameters);
const typeParamCount = length(baseSig.typeParameters);
if (typeArgCount >= minTypeArgumentCount && typeArgCount <= typeParamCount) {
if (typeArgCount <= typeParamCount) {
const sig = typeParamCount ? createSignatureInstantiation(baseSig, fillMissingTypeArguments(typeArguments, baseSig.typeParameters, /*errorNode*/ undefined)) : cloneSignature(baseSig);
sig.typeParameters = classType.localTypeParameters;
sig.resolvedReturnType = classType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(7,18): error TS2689: Cannot extend an interface 'Base'. Did you mean 'implements'?
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(19,18): error TS2510: Base constructors must all have the same return type.
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(27,18): error TS2510: Base constructors must all have the same return type.
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(45,18): error TS2508: No base constructor has the specified number of type arguments.
tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(56,18): error TS2510: Base constructors must all have the same return type.


==== tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts (3 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts (5 errors) ====
interface Base<T, U> {
x: T;
y: U;
Expand All @@ -25,6 +27,8 @@ tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts
declare function getBase(): BaseConstructor;

class D1 extends getBase() {
~~~~~~~~~
!!! error TS2510: Base constructors must all have the same return type.
constructor() {
super("abc", "def");
this.x = "x";
Expand All @@ -33,6 +37,8 @@ tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts
}

class D2 extends getBase() <number> {
~~~~~~~~~
!!! error TS2510: Base constructors must all have the same return type.
constructor() {
super(10);
super(10, 20);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//// [extendingFromGenericTypeWithMissingTypeArguments.ts]
class C1<T> {
c1_prop: T;
}
class D1 extends C1 {
d1_prop: number;
}

var d1 = new D1();
d1.c1_prop; // any
d1.d1_prop;


class C2<T> {
constructor(a: T) { }
c1_prop: T;
}
class D2 extends C2 {
d1_prop: number;
}

var d1 = new D2(2);
d1.c1_prop; // any
d1.d1_prop;



//// [extendingFromGenericTypeWithMissingTypeArguments.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var C1 = (function () {
function C1() {
}
return C1;
}());
var D1 = (function (_super) {
__extends(D1, _super);
function D1() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D1;
}(C1));
var d1 = new D1();
d1.c1_prop; // any
d1.d1_prop;
var C2 = (function () {
function C2(a) {
}
return C2;
}());
var D2 = (function (_super) {
__extends(D2, _super);
function D2() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D2;
}(C2));
var d1 = new D2(2);
d1.c1_prop; // any
d1.d1_prop;
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
=== tests/cases/compiler/extendingFromGenericTypeWithMissingTypeArguments.ts ===
class C1<T> {
>C1 : Symbol(C1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 0))
>T : Symbol(T, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 9))

c1_prop: T;
>c1_prop : Symbol(C1.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 13))
>T : Symbol(T, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 9))
}
class D1 extends C1 {
>D1 : Symbol(D1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 2, 1))
>C1 : Symbol(C1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 0))

d1_prop: number;
>d1_prop : Symbol(D1.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 3, 21))
}

var d1 = new D1();
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>D1 : Symbol(D1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 2, 1))

d1.c1_prop; // any
>d1.c1_prop : Symbol(C1.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 13))
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>c1_prop : Symbol(C1.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 13))

d1.d1_prop;
>d1.d1_prop : Symbol(D1.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 3, 21))
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>d1_prop : Symbol(D1.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 3, 21))


class C2<T> {
>C2 : Symbol(C2, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 9, 11))
>T : Symbol(T, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 12, 9))

constructor(a: T) { }
>a : Symbol(a, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 13, 16))
>T : Symbol(T, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 12, 9))

c1_prop: T;
>c1_prop : Symbol(C2.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 13, 25))
>T : Symbol(T, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 12, 9))
}
class D2 extends C2 {
>D2 : Symbol(D2, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 15, 1))
>C2 : Symbol(C2, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 9, 11))

d1_prop: number;
>d1_prop : Symbol(D2.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 16, 21))
}

var d1 = new D2(2);
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>D2 : Symbol(D2, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 15, 1))

d1.c1_prop; // any
>d1.c1_prop : Symbol(C1.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 13))
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>c1_prop : Symbol(C1.c1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 0, 13))

d1.d1_prop;
>d1.d1_prop : Symbol(D1.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 3, 21))
>d1 : Symbol(d1, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 7, 3), Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 20, 3))
>d1_prop : Symbol(D1.d1_prop, Decl(extendingFromGenericTypeWithMissingTypeArguments.ts, 3, 21))


Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
=== tests/cases/compiler/extendingFromGenericTypeWithMissingTypeArguments.ts ===
class C1<T> {
>C1 : C1<T>
>T : T

c1_prop: T;
>c1_prop : T
>T : T
}
class D1 extends C1 {
>D1 : D1
>C1 : C1<any>

d1_prop: number;
>d1_prop : number
}

var d1 = new D1();
>d1 : D1
>new D1() : D1
>D1 : typeof D1

d1.c1_prop; // any
>d1.c1_prop : any
>d1 : D1
>c1_prop : any

d1.d1_prop;
>d1.d1_prop : number
>d1 : D1
>d1_prop : number


class C2<T> {
>C2 : C2<T>
>T : T

constructor(a: T) { }
>a : T
>T : T

c1_prop: T;
>c1_prop : T
>T : T
}
class D2 extends C2 {
>D2 : D2
>C2 : C2<any>

d1_prop: number;
>d1_prop : number
}

var d1 = new D2(2);
>d1 : D1
>new D2(2) : D2
>D2 : typeof D2
>2 : 2

d1.c1_prop; // any
>d1.c1_prop : any
>d1 : D1
>c1_prop : any

d1.d1_prop;
>d1.d1_prop : number
>d1 : D1
>d1_prop : number


Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
tests/cases/compiler/recursiveBaseConstructorCreation3.ts(6,27): error TS2707: Type parameter 'T' implicitly has type 'any' because it was not supplied.
tests/cases/compiler/recursiveBaseConstructorCreation3.ts(9,11): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.


==== tests/cases/compiler/recursiveBaseConstructorCreation3.ts (2 errors) ====
==== tests/cases/compiler/recursiveBaseConstructorCreation3.ts (1 errors) ====
declare class base<T> {
}
declare class abc<T> extends base<T> {
Expand All @@ -13,7 +12,5 @@ tests/cases/compiler/recursiveBaseConstructorCreation3.ts(9,11): error TS2351: C
!!! error TS2707: Type parameter 'T' implicitly has type 'any' because it was not supplied.
}

var bar = new xyz(); // Error: Invalid 'new' expression.
~~~~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
var bar = new xyz();
var r: xyz = bar.foo;
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ declare class abc<T> extends base<T> {
declare class xyz extends abc {
}

var bar = new xyz(); // Error: Invalid 'new' expression.
var bar = new xyz();
var r: xyz = bar.foo;

//// [recursiveBaseConstructorCreation3.js]
var bar = new xyz(); // Error: Invalid 'new' expression.
var bar = new xyz();
var r = bar.foo;
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts(8,17): error TS2707: Type parameter 'T2' implicitly has type 'any' because it was not supplied.
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts(9,21): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts(9,27): error TS7006: Parameter 'value' implicitly has an 'any' type.


==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts (3 errors) ====
==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts (1 errors) ====

class A<T1, T2> {
constructor(private map: (value: T1) => T2) {
Expand All @@ -15,8 +13,4 @@ tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrec
~~~~~~~~~
!!! error TS2707: Type parameter 'T2' implicitly has type 'any' because it was not supplied.
constructor() { super(value => String(value)); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~~~~
!!! error TS7006: Parameter 'value' implicitly has an 'any' type.
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(8,17): error TS2707: Type parameter 'T1' implicitly has type 'any' because it was not supplied.
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(8,17): error TS2707: Type parameter 'T2' implicitly has type 'any' because it was not supplied.
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(9,21): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(9,27): error TS7006: Parameter 'value' implicitly has an 'any' type.


==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts (4 errors) ====
==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts (2 errors) ====

class A<T1, T2> {
constructor(private map: (value: T1) => T2) {
Expand All @@ -18,8 +16,4 @@ tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeAr
~
!!! error TS2707: Type parameter 'T2' implicitly has type 'any' because it was not supplied.
constructor() { super(value => String(value)); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~~~~
!!! error TS7006: Parameter 'value' implicitly has an 'any' type.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class C1<T> {
c1_prop: T;
}
class D1 extends C1 {
d1_prop: number;
}

var d1 = new D1();
d1.c1_prop; // any
d1.d1_prop;


class C2<T> {
constructor(a: T) { }
c1_prop: T;
}
class D2 extends C2 {
d1_prop: number;
}

var d1 = new D2(2);
d1.c1_prop; // any
d1.d1_prop;

2 changes: 1 addition & 1 deletion tests/cases/compiler/recursiveBaseConstructorCreation3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ declare class abc<T> extends base<T> {
declare class xyz extends abc {
}

var bar = new xyz(); // Error: Invalid 'new' expression.
var bar = new xyz();
var r: xyz = bar.foo;