Skip to content

Commit f3c073e

Browse files
committed
Merge pull request #2813 from Microsoft/lazyBaseTypes
Lazy base types
2 parents ec574c3 + c9d8c67 commit f3c073e

10 files changed

+307
-60
lines changed

src/compiler/checker.ts

Lines changed: 90 additions & 59 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,14 +1485,17 @@ module ts {
14851485
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
14861486
export interface InterfaceType extends ObjectType {
14871487
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
1488-
baseTypes: ObjectType[]; // Base types
14891488
declaredProperties: Symbol[]; // Declared members
14901489
declaredCallSignatures: Signature[]; // Declared call signatures
14911490
declaredConstructSignatures: Signature[]; // Declared construct signatures
14921491
declaredStringIndexType: Type; // Declared string index type
14931492
declaredNumberIndexType: Type; // Declared numeric index type
14941493
}
14951494

1495+
export interface InterfaceTypeWithBaseTypes extends InterfaceType {
1496+
baseTypes: ObjectType[];
1497+
}
1498+
14961499
// Type references (TypeFlags.Reference)
14971500
export interface TypeReference extends ObjectType {
14981501
target: GenericType; // Type reference target
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [classDoesNotDependOnBaseTypes.ts]
2+
var x: StringTree;
3+
if (typeof x !== "string") {
4+
x[0] = "";
5+
x[0] = new StringTreeCollection;
6+
}
7+
8+
type StringTree = string | StringTreeCollection;
9+
class StringTreeCollectionBase {
10+
[n: number]: StringTree;
11+
}
12+
13+
class StringTreeCollection extends StringTreeCollectionBase { }
14+
15+
//// [classDoesNotDependOnBaseTypes.js]
16+
var __extends = this.__extends || function (d, b) {
17+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
18+
function __() { this.constructor = d; }
19+
__.prototype = b.prototype;
20+
d.prototype = new __();
21+
};
22+
var x;
23+
if (typeof x !== "string") {
24+
x[0] = "";
25+
x[0] = new StringTreeCollection;
26+
}
27+
var StringTreeCollectionBase = (function () {
28+
function StringTreeCollectionBase() {
29+
}
30+
return StringTreeCollectionBase;
31+
})();
32+
var StringTreeCollection = (function (_super) {
33+
__extends(StringTreeCollection, _super);
34+
function StringTreeCollection() {
35+
_super.apply(this, arguments);
36+
}
37+
return StringTreeCollection;
38+
})(StringTreeCollectionBase);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/types/typeAliases/classDoesNotDependOnBaseTypes.ts ===
2+
var x: StringTree;
3+
>x : Symbol(x, Decl(classDoesNotDependOnBaseTypes.ts, 0, 3))
4+
>StringTree : Symbol(StringTree, Decl(classDoesNotDependOnBaseTypes.ts, 4, 1))
5+
6+
if (typeof x !== "string") {
7+
>x : Symbol(x, Decl(classDoesNotDependOnBaseTypes.ts, 0, 3))
8+
9+
x[0] = "";
10+
>x : Symbol(x, Decl(classDoesNotDependOnBaseTypes.ts, 0, 3))
11+
12+
x[0] = new StringTreeCollection;
13+
>x : Symbol(x, Decl(classDoesNotDependOnBaseTypes.ts, 0, 3))
14+
>StringTreeCollection : Symbol(StringTreeCollection, Decl(classDoesNotDependOnBaseTypes.ts, 9, 1))
15+
}
16+
17+
type StringTree = string | StringTreeCollection;
18+
>StringTree : Symbol(StringTree, Decl(classDoesNotDependOnBaseTypes.ts, 4, 1))
19+
>StringTreeCollection : Symbol(StringTreeCollection, Decl(classDoesNotDependOnBaseTypes.ts, 9, 1))
20+
21+
class StringTreeCollectionBase {
22+
>StringTreeCollectionBase : Symbol(StringTreeCollectionBase, Decl(classDoesNotDependOnBaseTypes.ts, 6, 48))
23+
24+
[n: number]: StringTree;
25+
>n : Symbol(n, Decl(classDoesNotDependOnBaseTypes.ts, 8, 5))
26+
>StringTree : Symbol(StringTree, Decl(classDoesNotDependOnBaseTypes.ts, 4, 1))
27+
}
28+
29+
class StringTreeCollection extends StringTreeCollectionBase { }
30+
>StringTreeCollection : Symbol(StringTreeCollection, Decl(classDoesNotDependOnBaseTypes.ts, 9, 1))
31+
>StringTreeCollectionBase : Symbol(StringTreeCollectionBase, Decl(classDoesNotDependOnBaseTypes.ts, 6, 48))
32+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== tests/cases/conformance/types/typeAliases/classDoesNotDependOnBaseTypes.ts ===
2+
var x: StringTree;
3+
>x : string | StringTreeCollection
4+
>StringTree : string | StringTreeCollection
5+
6+
if (typeof x !== "string") {
7+
>typeof x !== "string" : boolean
8+
>typeof x : string
9+
>x : string | StringTreeCollection
10+
>"string" : string
11+
12+
x[0] = "";
13+
>x[0] = "" : string
14+
>x[0] : string | StringTreeCollection
15+
>x : StringTreeCollection
16+
>0 : number
17+
>"" : string
18+
19+
x[0] = new StringTreeCollection;
20+
>x[0] = new StringTreeCollection : StringTreeCollection
21+
>x[0] : string | StringTreeCollection
22+
>x : StringTreeCollection
23+
>0 : number
24+
>new StringTreeCollection : StringTreeCollection
25+
>StringTreeCollection : typeof StringTreeCollection
26+
}
27+
28+
type StringTree = string | StringTreeCollection;
29+
>StringTree : string | StringTreeCollection
30+
>StringTreeCollection : StringTreeCollection
31+
32+
class StringTreeCollectionBase {
33+
>StringTreeCollectionBase : StringTreeCollectionBase
34+
35+
[n: number]: StringTree;
36+
>n : number
37+
>StringTree : string | StringTreeCollection
38+
}
39+
40+
class StringTreeCollection extends StringTreeCollectionBase { }
41+
>StringTreeCollection : StringTreeCollection
42+
>StringTreeCollectionBase : StringTreeCollectionBase
43+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [interfaceDoesNotDependOnBaseTypes.ts]
2+
var x: StringTree;
3+
if (typeof x !== "string") {
4+
x.push("");
5+
x.push([""]);
6+
}
7+
8+
type StringTree = string | StringTreeArray;
9+
interface StringTreeArray extends Array<StringTree> { }
10+
11+
//// [interfaceDoesNotDependOnBaseTypes.js]
12+
var x;
13+
if (typeof x !== "string") {
14+
x.push("");
15+
x.push([""]);
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/conformance/types/typeAliases/interfaceDoesNotDependOnBaseTypes.ts ===
2+
var x: StringTree;
3+
>x : Symbol(x, Decl(interfaceDoesNotDependOnBaseTypes.ts, 0, 3))
4+
>StringTree : Symbol(StringTree, Decl(interfaceDoesNotDependOnBaseTypes.ts, 4, 1))
5+
6+
if (typeof x !== "string") {
7+
>x : Symbol(x, Decl(interfaceDoesNotDependOnBaseTypes.ts, 0, 3))
8+
9+
x.push("");
10+
>x.push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29))
11+
>x : Symbol(x, Decl(interfaceDoesNotDependOnBaseTypes.ts, 0, 3))
12+
>push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29))
13+
14+
x.push([""]);
15+
>x.push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29))
16+
>x : Symbol(x, Decl(interfaceDoesNotDependOnBaseTypes.ts, 0, 3))
17+
>push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29))
18+
}
19+
20+
type StringTree = string | StringTreeArray;
21+
>StringTree : Symbol(StringTree, Decl(interfaceDoesNotDependOnBaseTypes.ts, 4, 1))
22+
>StringTreeArray : Symbol(StringTreeArray, Decl(interfaceDoesNotDependOnBaseTypes.ts, 6, 43))
23+
24+
interface StringTreeArray extends Array<StringTree> { }
25+
>StringTreeArray : Symbol(StringTreeArray, Decl(interfaceDoesNotDependOnBaseTypes.ts, 6, 43))
26+
>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11))
27+
>StringTree : Symbol(StringTree, Decl(interfaceDoesNotDependOnBaseTypes.ts, 4, 1))
28+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/conformance/types/typeAliases/interfaceDoesNotDependOnBaseTypes.ts ===
2+
var x: StringTree;
3+
>x : string | StringTreeArray
4+
>StringTree : string | StringTreeArray
5+
6+
if (typeof x !== "string") {
7+
>typeof x !== "string" : boolean
8+
>typeof x : string
9+
>x : string | StringTreeArray
10+
>"string" : string
11+
12+
x.push("");
13+
>x.push("") : number
14+
>x.push : (...items: (string | StringTreeArray)[]) => number
15+
>x : StringTreeArray
16+
>push : (...items: (string | StringTreeArray)[]) => number
17+
>"" : string
18+
19+
x.push([""]);
20+
>x.push([""]) : number
21+
>x.push : (...items: (string | StringTreeArray)[]) => number
22+
>x : StringTreeArray
23+
>push : (...items: (string | StringTreeArray)[]) => number
24+
>[""] : string[]
25+
>"" : string
26+
}
27+
28+
type StringTree = string | StringTreeArray;
29+
>StringTree : string | StringTreeArray
30+
>StringTreeArray : StringTreeArray
31+
32+
interface StringTreeArray extends Array<StringTree> { }
33+
>StringTreeArray : StringTreeArray
34+
>Array : T[]
35+
>StringTree : string | StringTreeArray
36+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var x: StringTree;
2+
if (typeof x !== "string") {
3+
x[0] = "";
4+
x[0] = new StringTreeCollection;
5+
}
6+
7+
type StringTree = string | StringTreeCollection;
8+
class StringTreeCollectionBase {
9+
[n: number]: StringTree;
10+
}
11+
12+
class StringTreeCollection extends StringTreeCollectionBase { }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var x: StringTree;
2+
if (typeof x !== "string") {
3+
x.push("");
4+
x.push([""]);
5+
}
6+
7+
type StringTree = string | StringTreeArray;
8+
interface StringTreeArray extends Array<StringTree> { }

0 commit comments

Comments
 (0)