mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 14:34:35 -06:00
Adding tests
This commit is contained in:
parent
47c9190408
commit
abd2a8526d
56
tests/baselines/reference/fluentClasses.js
Normal file
56
tests/baselines/reference/fluentClasses.js
Normal file
@ -0,0 +1,56 @@
|
||||
//// [fluentClasses.ts]
|
||||
class A {
|
||||
foo() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
bar() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class C extends B {
|
||||
baz() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
var c: C;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
|
||||
|
||||
//// [fluentClasses.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
A.prototype.foo = function () {
|
||||
return this;
|
||||
};
|
||||
return A;
|
||||
})();
|
||||
var B = (function (_super) {
|
||||
__extends(B, _super);
|
||||
function B() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
B.prototype.bar = function () {
|
||||
return this;
|
||||
};
|
||||
return B;
|
||||
})(A);
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype.baz = function () {
|
||||
return this;
|
||||
};
|
||||
return C;
|
||||
})(B);
|
||||
var c;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
47
tests/baselines/reference/fluentClasses.symbols
Normal file
47
tests/baselines/reference/fluentClasses.symbols
Normal file
@ -0,0 +1,47 @@
|
||||
=== tests/cases/conformance/types/thisType/fluentClasses.ts ===
|
||||
class A {
|
||||
>A : Symbol(A, Decl(fluentClasses.ts, 0, 0))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(foo, Decl(fluentClasses.ts, 0, 9))
|
||||
|
||||
return this;
|
||||
>this : Symbol(A, Decl(fluentClasses.ts, 0, 0))
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
>B : Symbol(B, Decl(fluentClasses.ts, 4, 1))
|
||||
>A : Symbol(A, Decl(fluentClasses.ts, 0, 0))
|
||||
|
||||
bar() {
|
||||
>bar : Symbol(bar, Decl(fluentClasses.ts, 5, 19))
|
||||
|
||||
return this;
|
||||
>this : Symbol(B, Decl(fluentClasses.ts, 4, 1))
|
||||
}
|
||||
}
|
||||
class C extends B {
|
||||
>C : Symbol(C, Decl(fluentClasses.ts, 9, 1))
|
||||
>B : Symbol(B, Decl(fluentClasses.ts, 4, 1))
|
||||
|
||||
baz() {
|
||||
>baz : Symbol(baz, Decl(fluentClasses.ts, 10, 19))
|
||||
|
||||
return this;
|
||||
>this : Symbol(C, Decl(fluentClasses.ts, 9, 1))
|
||||
}
|
||||
}
|
||||
var c: C;
|
||||
>c : Symbol(c, Decl(fluentClasses.ts, 15, 3))
|
||||
>C : Symbol(C, Decl(fluentClasses.ts, 9, 1))
|
||||
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
>z : Symbol(z, Decl(fluentClasses.ts, 16, 3))
|
||||
>c.foo().bar().baz : Symbol(C.baz, Decl(fluentClasses.ts, 10, 19))
|
||||
>c.foo().bar : Symbol(B.bar, Decl(fluentClasses.ts, 5, 19))
|
||||
>c.foo : Symbol(A.foo, Decl(fluentClasses.ts, 0, 9))
|
||||
>c : Symbol(c, Decl(fluentClasses.ts, 15, 3))
|
||||
>foo : Symbol(A.foo, Decl(fluentClasses.ts, 0, 9))
|
||||
>bar : Symbol(B.bar, Decl(fluentClasses.ts, 5, 19))
|
||||
>baz : Symbol(C.baz, Decl(fluentClasses.ts, 10, 19))
|
||||
|
||||
50
tests/baselines/reference/fluentClasses.types
Normal file
50
tests/baselines/reference/fluentClasses.types
Normal file
@ -0,0 +1,50 @@
|
||||
=== tests/cases/conformance/types/thisType/fluentClasses.ts ===
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
foo() {
|
||||
>foo : () => this
|
||||
|
||||
return this;
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
bar() {
|
||||
>bar : () => this
|
||||
|
||||
return this;
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
class C extends B {
|
||||
>C : C
|
||||
>B : B
|
||||
|
||||
baz() {
|
||||
>baz : () => this
|
||||
|
||||
return this;
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
var c: C;
|
||||
>c : C
|
||||
>C : C
|
||||
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
>z : C
|
||||
>c.foo().bar().baz() : C
|
||||
>c.foo().bar().baz : () => C
|
||||
>c.foo().bar() : C
|
||||
>c.foo().bar : () => C
|
||||
>c.foo() : C
|
||||
>c.foo : () => C
|
||||
>c : C
|
||||
>foo : () => C
|
||||
>bar : () => C
|
||||
>baz : () => C
|
||||
|
||||
17
tests/baselines/reference/fluentInterfaces.js
Normal file
17
tests/baselines/reference/fluentInterfaces.js
Normal file
@ -0,0 +1,17 @@
|
||||
//// [fluentInterfaces.ts]
|
||||
interface A {
|
||||
foo(): this;
|
||||
}
|
||||
interface B extends A {
|
||||
bar(): this;
|
||||
}
|
||||
interface C extends B {
|
||||
baz(): this;
|
||||
}
|
||||
var c: C;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
|
||||
|
||||
//// [fluentInterfaces.js]
|
||||
var c;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
35
tests/baselines/reference/fluentInterfaces.symbols
Normal file
35
tests/baselines/reference/fluentInterfaces.symbols
Normal file
@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/types/thisType/fluentInterfaces.ts ===
|
||||
interface A {
|
||||
>A : Symbol(A, Decl(fluentInterfaces.ts, 0, 0))
|
||||
|
||||
foo(): this;
|
||||
>foo : Symbol(foo, Decl(fluentInterfaces.ts, 0, 13))
|
||||
}
|
||||
interface B extends A {
|
||||
>B : Symbol(B, Decl(fluentInterfaces.ts, 2, 1))
|
||||
>A : Symbol(A, Decl(fluentInterfaces.ts, 0, 0))
|
||||
|
||||
bar(): this;
|
||||
>bar : Symbol(bar, Decl(fluentInterfaces.ts, 3, 23))
|
||||
}
|
||||
interface C extends B {
|
||||
>C : Symbol(C, Decl(fluentInterfaces.ts, 5, 1))
|
||||
>B : Symbol(B, Decl(fluentInterfaces.ts, 2, 1))
|
||||
|
||||
baz(): this;
|
||||
>baz : Symbol(baz, Decl(fluentInterfaces.ts, 6, 23))
|
||||
}
|
||||
var c: C;
|
||||
>c : Symbol(c, Decl(fluentInterfaces.ts, 9, 3))
|
||||
>C : Symbol(C, Decl(fluentInterfaces.ts, 5, 1))
|
||||
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
>z : Symbol(z, Decl(fluentInterfaces.ts, 10, 3))
|
||||
>c.foo().bar().baz : Symbol(C.baz, Decl(fluentInterfaces.ts, 6, 23))
|
||||
>c.foo().bar : Symbol(B.bar, Decl(fluentInterfaces.ts, 3, 23))
|
||||
>c.foo : Symbol(A.foo, Decl(fluentInterfaces.ts, 0, 13))
|
||||
>c : Symbol(c, Decl(fluentInterfaces.ts, 9, 3))
|
||||
>foo : Symbol(A.foo, Decl(fluentInterfaces.ts, 0, 13))
|
||||
>bar : Symbol(B.bar, Decl(fluentInterfaces.ts, 3, 23))
|
||||
>baz : Symbol(C.baz, Decl(fluentInterfaces.ts, 6, 23))
|
||||
|
||||
38
tests/baselines/reference/fluentInterfaces.types
Normal file
38
tests/baselines/reference/fluentInterfaces.types
Normal file
@ -0,0 +1,38 @@
|
||||
=== tests/cases/conformance/types/thisType/fluentInterfaces.ts ===
|
||||
interface A {
|
||||
>A : A
|
||||
|
||||
foo(): this;
|
||||
>foo : () => this
|
||||
}
|
||||
interface B extends A {
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
bar(): this;
|
||||
>bar : () => this
|
||||
}
|
||||
interface C extends B {
|
||||
>C : C
|
||||
>B : B
|
||||
|
||||
baz(): this;
|
||||
>baz : () => this
|
||||
}
|
||||
var c: C;
|
||||
>c : C
|
||||
>C : C
|
||||
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
>z : C
|
||||
>c.foo().bar().baz() : C
|
||||
>c.foo().bar().baz : () => C
|
||||
>c.foo().bar() : C
|
||||
>c.foo().bar : () => C
|
||||
>c.foo() : C
|
||||
>c.foo : () => C
|
||||
>c : C
|
||||
>foo : () => C
|
||||
>bar : () => C
|
||||
>baz : () => C
|
||||
|
||||
149
tests/baselines/reference/thisTypeErrors.errors.txt
Normal file
149
tests/baselines/reference/thisTypeErrors.errors.txt
Normal file
@ -0,0 +1,149 @@
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(36,20): error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/thisType/thisTypeErrors.ts (30 errors) ====
|
||||
var x1: this;
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
var x2: { a: this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
var x3: this[];
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
|
||||
function f1(x: this): this {
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
var y: this;
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
return this;
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
a: { x: this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
b: { (): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
c: { new (): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
d: { [x: string]: this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
e: { f(x: this): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
}
|
||||
|
||||
class C1 {
|
||||
a: { x: this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
b: { (): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
c: { new (): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
d: { [x: string]: this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
e: { f(x: this): this };
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
}
|
||||
|
||||
class C2 {
|
||||
static x: this;
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
static y = <this>undefined;
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
static foo(x: this): this {
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
namespace N1 {
|
||||
export var x: this;
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
export var y = this;
|
||||
~~~~
|
||||
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
}
|
||||
|
||||
class C3 {
|
||||
x1 = {
|
||||
g(x: this): this {
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
f() {
|
||||
function g(x: this): this {
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
return undefined;
|
||||
}
|
||||
let x2 = {
|
||||
h(x: this): this {
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
~~~~
|
||||
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
104
tests/baselines/reference/thisTypeErrors.js
Normal file
104
tests/baselines/reference/thisTypeErrors.js
Normal file
@ -0,0 +1,104 @@
|
||||
//// [thisTypeErrors.ts]
|
||||
var x1: this;
|
||||
var x2: { a: this };
|
||||
var x3: this[];
|
||||
|
||||
function f1(x: this): this {
|
||||
var y: this;
|
||||
return this;
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
a: { x: this };
|
||||
b: { (): this };
|
||||
c: { new (): this };
|
||||
d: { [x: string]: this };
|
||||
e: { f(x: this): this };
|
||||
}
|
||||
|
||||
class C1 {
|
||||
a: { x: this };
|
||||
b: { (): this };
|
||||
c: { new (): this };
|
||||
d: { [x: string]: this };
|
||||
e: { f(x: this): this };
|
||||
}
|
||||
|
||||
class C2 {
|
||||
static x: this;
|
||||
static y = <this>undefined;
|
||||
static foo(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
namespace N1 {
|
||||
export var x: this;
|
||||
export var y = this;
|
||||
}
|
||||
|
||||
class C3 {
|
||||
x1 = {
|
||||
g(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
f() {
|
||||
function g(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
let x2 = {
|
||||
h(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [thisTypeErrors.js]
|
||||
var x1;
|
||||
var x2;
|
||||
var x3;
|
||||
function f1(x) {
|
||||
var y;
|
||||
return this;
|
||||
}
|
||||
var C1 = (function () {
|
||||
function C1() {
|
||||
}
|
||||
return C1;
|
||||
})();
|
||||
var C2 = (function () {
|
||||
function C2() {
|
||||
}
|
||||
C2.foo = function (x) {
|
||||
return undefined;
|
||||
};
|
||||
C2.y = undefined;
|
||||
return C2;
|
||||
})();
|
||||
var N1;
|
||||
(function (N1) {
|
||||
N1.y = this;
|
||||
})(N1 || (N1 = {}));
|
||||
var C3 = (function () {
|
||||
function C3() {
|
||||
this.x1 = {
|
||||
g: function (x) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
C3.prototype.f = function () {
|
||||
function g(x) {
|
||||
return undefined;
|
||||
}
|
||||
var x2 = {
|
||||
h: function (x) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
return C3;
|
||||
})();
|
||||
91
tests/baselines/reference/thisTypeInClasses.js
Normal file
91
tests/baselines/reference/thisTypeInClasses.js
Normal file
@ -0,0 +1,91 @@
|
||||
//// [thisTypeInClasses.ts]
|
||||
class C1 {
|
||||
x: this;
|
||||
f(x: this): this { return undefined; }
|
||||
constructor(x: this) { }
|
||||
}
|
||||
|
||||
class C2 {
|
||||
[x: string]: this;
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
x: T;
|
||||
y: this;
|
||||
}
|
||||
|
||||
class C3 {
|
||||
a: this[];
|
||||
b: [this, this];
|
||||
c: this | Date;
|
||||
d: this & Date;
|
||||
e: (((this)));
|
||||
f: (x: this) => this;
|
||||
g: new (x: this) => this;
|
||||
h: Foo<this>;
|
||||
i: Foo<this | (() => this)>;
|
||||
j: (x: any) => x is this;
|
||||
}
|
||||
|
||||
declare class C4 {
|
||||
x: this;
|
||||
f(x: this): this;
|
||||
}
|
||||
|
||||
class C5 {
|
||||
foo() {
|
||||
let f1 = (x: this): this => this;
|
||||
let f2 = (x: this) => this;
|
||||
let f3 = (x: this) => (y: this) => this;
|
||||
let f4 = (x: this) => {
|
||||
let g = (y: this) => {
|
||||
return () => this;
|
||||
}
|
||||
return g(this);
|
||||
}
|
||||
}
|
||||
bar() {
|
||||
let x1 = <this>undefined;
|
||||
let x2 = undefined as this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [thisTypeInClasses.js]
|
||||
var C1 = (function () {
|
||||
function C1(x) {
|
||||
}
|
||||
C1.prototype.f = function (x) { return undefined; };
|
||||
return C1;
|
||||
})();
|
||||
var C2 = (function () {
|
||||
function C2() {
|
||||
}
|
||||
return C2;
|
||||
})();
|
||||
var C3 = (function () {
|
||||
function C3() {
|
||||
}
|
||||
return C3;
|
||||
})();
|
||||
var C5 = (function () {
|
||||
function C5() {
|
||||
}
|
||||
C5.prototype.foo = function () {
|
||||
var _this = this;
|
||||
var f1 = function (x) { return _this; };
|
||||
var f2 = function (x) { return _this; };
|
||||
var f3 = function (x) { return function (y) { return _this; }; };
|
||||
var f4 = function (x) {
|
||||
var g = function (y) {
|
||||
return function () { return _this; };
|
||||
};
|
||||
return g(_this);
|
||||
};
|
||||
};
|
||||
C5.prototype.bar = function () {
|
||||
var x1 = undefined;
|
||||
var x2 = undefined;
|
||||
};
|
||||
return C5;
|
||||
})();
|
||||
140
tests/baselines/reference/thisTypeInClasses.symbols
Normal file
140
tests/baselines/reference/thisTypeInClasses.symbols
Normal file
@ -0,0 +1,140 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInClasses.ts ===
|
||||
class C1 {
|
||||
>C1 : Symbol(C1, Decl(thisTypeInClasses.ts, 0, 0))
|
||||
|
||||
x: this;
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 0, 10))
|
||||
|
||||
f(x: this): this { return undefined; }
|
||||
>f : Symbol(f, Decl(thisTypeInClasses.ts, 1, 12))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 2, 6))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
constructor(x: this) { }
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 3, 16))
|
||||
}
|
||||
|
||||
class C2 {
|
||||
>C2 : Symbol(C2, Decl(thisTypeInClasses.ts, 4, 1))
|
||||
|
||||
[x: string]: this;
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 7, 5))
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInClasses.ts, 8, 1))
|
||||
>T : Symbol(T, Decl(thisTypeInClasses.ts, 10, 14))
|
||||
|
||||
x: T;
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 10, 18))
|
||||
>T : Symbol(T, Decl(thisTypeInClasses.ts, 10, 14))
|
||||
|
||||
y: this;
|
||||
>y : Symbol(y, Decl(thisTypeInClasses.ts, 11, 9))
|
||||
}
|
||||
|
||||
class C3 {
|
||||
>C3 : Symbol(C3, Decl(thisTypeInClasses.ts, 13, 1))
|
||||
|
||||
a: this[];
|
||||
>a : Symbol(a, Decl(thisTypeInClasses.ts, 15, 10))
|
||||
|
||||
b: [this, this];
|
||||
>b : Symbol(b, Decl(thisTypeInClasses.ts, 16, 14))
|
||||
|
||||
c: this | Date;
|
||||
>c : Symbol(c, Decl(thisTypeInClasses.ts, 17, 20))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
d: this & Date;
|
||||
>d : Symbol(d, Decl(thisTypeInClasses.ts, 18, 19))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
e: (((this)));
|
||||
>e : Symbol(e, Decl(thisTypeInClasses.ts, 19, 19))
|
||||
|
||||
f: (x: this) => this;
|
||||
>f : Symbol(f, Decl(thisTypeInClasses.ts, 20, 18))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 21, 8))
|
||||
|
||||
g: new (x: this) => this;
|
||||
>g : Symbol(g, Decl(thisTypeInClasses.ts, 21, 25))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 22, 12))
|
||||
|
||||
h: Foo<this>;
|
||||
>h : Symbol(h, Decl(thisTypeInClasses.ts, 22, 29))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInClasses.ts, 8, 1))
|
||||
|
||||
i: Foo<this | (() => this)>;
|
||||
>i : Symbol(i, Decl(thisTypeInClasses.ts, 23, 17))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInClasses.ts, 8, 1))
|
||||
|
||||
j: (x: any) => x is this;
|
||||
>j : Symbol(j, Decl(thisTypeInClasses.ts, 24, 32))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 25, 8))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 25, 8))
|
||||
}
|
||||
|
||||
declare class C4 {
|
||||
>C4 : Symbol(C4, Decl(thisTypeInClasses.ts, 26, 1))
|
||||
|
||||
x: this;
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 28, 18))
|
||||
|
||||
f(x: this): this;
|
||||
>f : Symbol(f, Decl(thisTypeInClasses.ts, 29, 12))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 30, 6))
|
||||
}
|
||||
|
||||
class C5 {
|
||||
>C5 : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(foo, Decl(thisTypeInClasses.ts, 33, 10))
|
||||
|
||||
let f1 = (x: this): this => this;
|
||||
>f1 : Symbol(f1, Decl(thisTypeInClasses.ts, 35, 11))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 35, 18))
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
|
||||
let f2 = (x: this) => this;
|
||||
>f2 : Symbol(f2, Decl(thisTypeInClasses.ts, 36, 11))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 36, 18))
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
|
||||
let f3 = (x: this) => (y: this) => this;
|
||||
>f3 : Symbol(f3, Decl(thisTypeInClasses.ts, 37, 11))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 37, 18))
|
||||
>y : Symbol(y, Decl(thisTypeInClasses.ts, 37, 31))
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
|
||||
let f4 = (x: this) => {
|
||||
>f4 : Symbol(f4, Decl(thisTypeInClasses.ts, 38, 11))
|
||||
>x : Symbol(x, Decl(thisTypeInClasses.ts, 38, 18))
|
||||
|
||||
let g = (y: this) => {
|
||||
>g : Symbol(g, Decl(thisTypeInClasses.ts, 39, 15))
|
||||
>y : Symbol(y, Decl(thisTypeInClasses.ts, 39, 21))
|
||||
|
||||
return () => this;
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
}
|
||||
return g(this);
|
||||
>g : Symbol(g, Decl(thisTypeInClasses.ts, 39, 15))
|
||||
>this : Symbol(C5, Decl(thisTypeInClasses.ts, 31, 1))
|
||||
}
|
||||
}
|
||||
bar() {
|
||||
>bar : Symbol(bar, Decl(thisTypeInClasses.ts, 44, 5))
|
||||
|
||||
let x1 = <this>undefined;
|
||||
>x1 : Symbol(x1, Decl(thisTypeInClasses.ts, 46, 11))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
let x2 = undefined as this;
|
||||
>x2 : Symbol(x2, Decl(thisTypeInClasses.ts, 47, 11))
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
150
tests/baselines/reference/thisTypeInClasses.types
Normal file
150
tests/baselines/reference/thisTypeInClasses.types
Normal file
@ -0,0 +1,150 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInClasses.ts ===
|
||||
class C1 {
|
||||
>C1 : C1
|
||||
|
||||
x: this;
|
||||
>x : this
|
||||
|
||||
f(x: this): this { return undefined; }
|
||||
>f : (x: this) => this
|
||||
>x : this
|
||||
>undefined : undefined
|
||||
|
||||
constructor(x: this) { }
|
||||
>x : this
|
||||
}
|
||||
|
||||
class C2 {
|
||||
>C2 : C2
|
||||
|
||||
[x: string]: this;
|
||||
>x : string
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
x: T;
|
||||
>x : T
|
||||
>T : T
|
||||
|
||||
y: this;
|
||||
>y : this
|
||||
}
|
||||
|
||||
class C3 {
|
||||
>C3 : C3
|
||||
|
||||
a: this[];
|
||||
>a : this[]
|
||||
|
||||
b: [this, this];
|
||||
>b : [this, this]
|
||||
|
||||
c: this | Date;
|
||||
>c : this | Date
|
||||
>Date : Date
|
||||
|
||||
d: this & Date;
|
||||
>d : this & Date
|
||||
>Date : Date
|
||||
|
||||
e: (((this)));
|
||||
>e : this
|
||||
|
||||
f: (x: this) => this;
|
||||
>f : (x: this) => this
|
||||
>x : this
|
||||
|
||||
g: new (x: this) => this;
|
||||
>g : new (x: this) => this
|
||||
>x : this
|
||||
|
||||
h: Foo<this>;
|
||||
>h : Foo<this>
|
||||
>Foo : Foo<T>
|
||||
|
||||
i: Foo<this | (() => this)>;
|
||||
>i : Foo<this | (() => this)>
|
||||
>Foo : Foo<T>
|
||||
|
||||
j: (x: any) => x is this;
|
||||
>j : (x: any) => x is this
|
||||
>x : any
|
||||
>x : any
|
||||
}
|
||||
|
||||
declare class C4 {
|
||||
>C4 : C4
|
||||
|
||||
x: this;
|
||||
>x : this
|
||||
|
||||
f(x: this): this;
|
||||
>f : (x: this) => this
|
||||
>x : this
|
||||
}
|
||||
|
||||
class C5 {
|
||||
>C5 : C5
|
||||
|
||||
foo() {
|
||||
>foo : () => void
|
||||
|
||||
let f1 = (x: this): this => this;
|
||||
>f1 : (x: this) => this
|
||||
>(x: this): this => this : (x: this) => this
|
||||
>x : this
|
||||
>this : this
|
||||
>this : this
|
||||
|
||||
let f2 = (x: this) => this;
|
||||
>f2 : (x: this) => this
|
||||
>(x: this) => this : (x: this) => this
|
||||
>x : this
|
||||
>this : this
|
||||
|
||||
let f3 = (x: this) => (y: this) => this;
|
||||
>f3 : (x: this) => (y: this) => this
|
||||
>(x: this) => (y: this) => this : (x: this) => (y: this) => this
|
||||
>x : this
|
||||
>(y: this) => this : (y: this) => this
|
||||
>y : this
|
||||
>this : this
|
||||
|
||||
let f4 = (x: this) => {
|
||||
>f4 : (x: this) => () => this
|
||||
>(x: this) => { let g = (y: this) => { return () => this; } return g(this); } : (x: this) => () => this
|
||||
>x : this
|
||||
|
||||
let g = (y: this) => {
|
||||
>g : (y: this) => () => this
|
||||
>(y: this) => { return () => this; } : (y: this) => () => this
|
||||
>y : this
|
||||
|
||||
return () => this;
|
||||
>() => this : () => this
|
||||
>this : this
|
||||
}
|
||||
return g(this);
|
||||
>g(this) : () => this
|
||||
>g : (y: this) => () => this
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
bar() {
|
||||
>bar : () => void
|
||||
|
||||
let x1 = <this>undefined;
|
||||
>x1 : this
|
||||
><this>undefined : this
|
||||
>undefined : undefined
|
||||
|
||||
let x2 = undefined as this;
|
||||
>x2 : this
|
||||
>undefined as this : this
|
||||
>undefined : undefined
|
||||
}
|
||||
}
|
||||
|
||||
32
tests/baselines/reference/thisTypeInInterfaces.js
Normal file
32
tests/baselines/reference/thisTypeInInterfaces.js
Normal file
@ -0,0 +1,32 @@
|
||||
//// [thisTypeInInterfaces.ts]
|
||||
interface I1 {
|
||||
x: this;
|
||||
f(x: this): this;
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
(x: this): this;
|
||||
new (x: this): this;
|
||||
[x: string]: this;
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
x: T;
|
||||
y: this;
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
a: this[];
|
||||
b: [this, this];
|
||||
c: this | Date;
|
||||
d: this & Date;
|
||||
e: (((this)));
|
||||
f: (x: this) => this;
|
||||
g: new (x: this) => this;
|
||||
h: Foo<this>;
|
||||
i: Foo<this | (() => this)>;
|
||||
j: (x: any) => x is this;
|
||||
}
|
||||
|
||||
|
||||
//// [thisTypeInInterfaces.js]
|
||||
79
tests/baselines/reference/thisTypeInInterfaces.symbols
Normal file
79
tests/baselines/reference/thisTypeInInterfaces.symbols
Normal file
@ -0,0 +1,79 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInInterfaces.ts ===
|
||||
interface I1 {
|
||||
>I1 : Symbol(I1, Decl(thisTypeInInterfaces.ts, 0, 0))
|
||||
|
||||
x: this;
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 0, 14))
|
||||
|
||||
f(x: this): this;
|
||||
>f : Symbol(f, Decl(thisTypeInInterfaces.ts, 1, 12))
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 2, 6))
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
>I2 : Symbol(I2, Decl(thisTypeInInterfaces.ts, 3, 1))
|
||||
|
||||
(x: this): this;
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 6, 5))
|
||||
|
||||
new (x: this): this;
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 7, 9))
|
||||
|
||||
[x: string]: this;
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 8, 5))
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInInterfaces.ts, 9, 1))
|
||||
>T : Symbol(T, Decl(thisTypeInInterfaces.ts, 11, 14))
|
||||
|
||||
x: T;
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 11, 18))
|
||||
>T : Symbol(T, Decl(thisTypeInInterfaces.ts, 11, 14))
|
||||
|
||||
y: this;
|
||||
>y : Symbol(y, Decl(thisTypeInInterfaces.ts, 12, 9))
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
>I3 : Symbol(I3, Decl(thisTypeInInterfaces.ts, 14, 1))
|
||||
|
||||
a: this[];
|
||||
>a : Symbol(a, Decl(thisTypeInInterfaces.ts, 16, 14))
|
||||
|
||||
b: [this, this];
|
||||
>b : Symbol(b, Decl(thisTypeInInterfaces.ts, 17, 14))
|
||||
|
||||
c: this | Date;
|
||||
>c : Symbol(c, Decl(thisTypeInInterfaces.ts, 18, 20))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
d: this & Date;
|
||||
>d : Symbol(d, Decl(thisTypeInInterfaces.ts, 19, 19))
|
||||
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
|
||||
|
||||
e: (((this)));
|
||||
>e : Symbol(e, Decl(thisTypeInInterfaces.ts, 20, 19))
|
||||
|
||||
f: (x: this) => this;
|
||||
>f : Symbol(f, Decl(thisTypeInInterfaces.ts, 21, 18))
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 22, 8))
|
||||
|
||||
g: new (x: this) => this;
|
||||
>g : Symbol(g, Decl(thisTypeInInterfaces.ts, 22, 25))
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 23, 12))
|
||||
|
||||
h: Foo<this>;
|
||||
>h : Symbol(h, Decl(thisTypeInInterfaces.ts, 23, 29))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInInterfaces.ts, 9, 1))
|
||||
|
||||
i: Foo<this | (() => this)>;
|
||||
>i : Symbol(i, Decl(thisTypeInInterfaces.ts, 24, 17))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInInterfaces.ts, 9, 1))
|
||||
|
||||
j: (x: any) => x is this;
|
||||
>j : Symbol(j, Decl(thisTypeInInterfaces.ts, 25, 32))
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 26, 8))
|
||||
>x : Symbol(x, Decl(thisTypeInInterfaces.ts, 26, 8))
|
||||
}
|
||||
|
||||
79
tests/baselines/reference/thisTypeInInterfaces.types
Normal file
79
tests/baselines/reference/thisTypeInInterfaces.types
Normal file
@ -0,0 +1,79 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInInterfaces.ts ===
|
||||
interface I1 {
|
||||
>I1 : I1
|
||||
|
||||
x: this;
|
||||
>x : this
|
||||
|
||||
f(x: this): this;
|
||||
>f : (x: this) => this
|
||||
>x : this
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
>I2 : I2
|
||||
|
||||
(x: this): this;
|
||||
>x : this
|
||||
|
||||
new (x: this): this;
|
||||
>x : this
|
||||
|
||||
[x: string]: this;
|
||||
>x : string
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
x: T;
|
||||
>x : T
|
||||
>T : T
|
||||
|
||||
y: this;
|
||||
>y : this
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
>I3 : I3
|
||||
|
||||
a: this[];
|
||||
>a : this[]
|
||||
|
||||
b: [this, this];
|
||||
>b : [this, this]
|
||||
|
||||
c: this | Date;
|
||||
>c : this | Date
|
||||
>Date : Date
|
||||
|
||||
d: this & Date;
|
||||
>d : this & Date
|
||||
>Date : Date
|
||||
|
||||
e: (((this)));
|
||||
>e : this
|
||||
|
||||
f: (x: this) => this;
|
||||
>f : (x: this) => this
|
||||
>x : this
|
||||
|
||||
g: new (x: this) => this;
|
||||
>g : new (x: this) => this
|
||||
>x : this
|
||||
|
||||
h: Foo<this>;
|
||||
>h : Foo<this>
|
||||
>Foo : Foo<T>
|
||||
|
||||
i: Foo<this | (() => this)>;
|
||||
>i : Foo<this | (() => this)>
|
||||
>Foo : Foo<T>
|
||||
|
||||
j: (x: any) => x is this;
|
||||
>j : (x: any) => x is this
|
||||
>x : any
|
||||
>x : any
|
||||
}
|
||||
|
||||
54
tests/baselines/reference/typeRelationships.errors.txt
Normal file
54
tests/baselines/reference/typeRelationships.errors.txt
Normal file
@ -0,0 +1,54 @@
|
||||
tests/cases/conformance/types/thisType/typeRelationships.ts(9,9): error TS2322: Type 'C' is not assignable to type 'this'.
|
||||
tests/cases/conformance/types/thisType/typeRelationships.ts(35,9): error TS2322: Type 'C' is not assignable to type 'D'.
|
||||
Property 'self1' is missing in type 'C'.
|
||||
tests/cases/conformance/types/thisType/typeRelationships.ts(36,9): error TS2322: Type 'D' is not assignable to type 'this'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/thisType/typeRelationships.ts (3 errors) ====
|
||||
class C {
|
||||
self = this;
|
||||
c = new C();
|
||||
foo() {
|
||||
return this;
|
||||
}
|
||||
f1() {
|
||||
this.c = this.self;
|
||||
this.self = this.c; // Error
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'this'.
|
||||
}
|
||||
f2() {
|
||||
var a: C[];
|
||||
var a = [this, this.c]; // C[] since this is subtype of C
|
||||
var b: this[];
|
||||
var b = [this, this.self, null, undefined];
|
||||
}
|
||||
f3(b: boolean) {
|
||||
return b ? this.c : this.self; // Should be C
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
self1 = this;
|
||||
self2 = this.self;
|
||||
self3 = this.foo();
|
||||
d = new D();
|
||||
bar() {
|
||||
this.self = this.self1;
|
||||
this.self = this.self2;
|
||||
this.self = this.self3;
|
||||
this.self1 = this.self;
|
||||
this.self2 = this.self;
|
||||
this.self3 = this.self;
|
||||
this.d = this.self;
|
||||
this.d = this.c; // Error
|
||||
~~~~~~
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'D'.
|
||||
!!! error TS2322: Property 'self1' is missing in type 'C'.
|
||||
this.self = this.d; // Error
|
||||
~~~~~~~~~
|
||||
!!! error TS2322: Type 'D' is not assignable to type 'this'.
|
||||
this.c = this.d;
|
||||
}
|
||||
}
|
||||
|
||||
94
tests/baselines/reference/typeRelationships.js
Normal file
94
tests/baselines/reference/typeRelationships.js
Normal file
@ -0,0 +1,94 @@
|
||||
//// [typeRelationships.ts]
|
||||
class C {
|
||||
self = this;
|
||||
c = new C();
|
||||
foo() {
|
||||
return this;
|
||||
}
|
||||
f1() {
|
||||
this.c = this.self;
|
||||
this.self = this.c; // Error
|
||||
}
|
||||
f2() {
|
||||
var a: C[];
|
||||
var a = [this, this.c]; // C[] since this is subtype of C
|
||||
var b: this[];
|
||||
var b = [this, this.self, null, undefined];
|
||||
}
|
||||
f3(b: boolean) {
|
||||
return b ? this.c : this.self; // Should be C
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
self1 = this;
|
||||
self2 = this.self;
|
||||
self3 = this.foo();
|
||||
d = new D();
|
||||
bar() {
|
||||
this.self = this.self1;
|
||||
this.self = this.self2;
|
||||
this.self = this.self3;
|
||||
this.self1 = this.self;
|
||||
this.self2 = this.self;
|
||||
this.self3 = this.self;
|
||||
this.d = this.self;
|
||||
this.d = this.c; // Error
|
||||
this.self = this.d; // Error
|
||||
this.c = this.d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [typeRelationships.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var C = (function () {
|
||||
function C() {
|
||||
this.self = this;
|
||||
this.c = new C();
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
return this;
|
||||
};
|
||||
C.prototype.f1 = function () {
|
||||
this.c = this.self;
|
||||
this.self = this.c; // Error
|
||||
};
|
||||
C.prototype.f2 = function () {
|
||||
var a;
|
||||
var a = [this, this.c]; // C[] since this is subtype of C
|
||||
var b;
|
||||
var b = [this, this.self, null, undefined];
|
||||
};
|
||||
C.prototype.f3 = function (b) {
|
||||
return b ? this.c : this.self; // Should be C
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
var D = (function (_super) {
|
||||
__extends(D, _super);
|
||||
function D() {
|
||||
_super.apply(this, arguments);
|
||||
this.self1 = this;
|
||||
this.self2 = this.self;
|
||||
this.self3 = this.foo();
|
||||
this.d = new D();
|
||||
}
|
||||
D.prototype.bar = function () {
|
||||
this.self = this.self1;
|
||||
this.self = this.self2;
|
||||
this.self = this.self3;
|
||||
this.self1 = this.self;
|
||||
this.self2 = this.self;
|
||||
this.self3 = this.self;
|
||||
this.d = this.self;
|
||||
this.d = this.c; // Error
|
||||
this.self = this.d; // Error
|
||||
this.c = this.d;
|
||||
};
|
||||
return D;
|
||||
})(C);
|
||||
17
tests/cases/conformance/types/thisType/fluentClasses.ts
Normal file
17
tests/cases/conformance/types/thisType/fluentClasses.ts
Normal file
@ -0,0 +1,17 @@
|
||||
class A {
|
||||
foo() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class B extends A {
|
||||
bar() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class C extends B {
|
||||
baz() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
var c: C;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
11
tests/cases/conformance/types/thisType/fluentInterfaces.ts
Normal file
11
tests/cases/conformance/types/thisType/fluentInterfaces.ts
Normal file
@ -0,0 +1,11 @@
|
||||
interface A {
|
||||
foo(): this;
|
||||
}
|
||||
interface B extends A {
|
||||
bar(): this;
|
||||
}
|
||||
interface C extends B {
|
||||
baz(): this;
|
||||
}
|
||||
var c: C;
|
||||
var z = c.foo().bar().baz(); // Fluent pattern
|
||||
55
tests/cases/conformance/types/thisType/thisTypeErrors.ts
Normal file
55
tests/cases/conformance/types/thisType/thisTypeErrors.ts
Normal file
@ -0,0 +1,55 @@
|
||||
var x1: this;
|
||||
var x2: { a: this };
|
||||
var x3: this[];
|
||||
|
||||
function f1(x: this): this {
|
||||
var y: this;
|
||||
return this;
|
||||
}
|
||||
|
||||
interface I1 {
|
||||
a: { x: this };
|
||||
b: { (): this };
|
||||
c: { new (): this };
|
||||
d: { [x: string]: this };
|
||||
e: { f(x: this): this };
|
||||
}
|
||||
|
||||
class C1 {
|
||||
a: { x: this };
|
||||
b: { (): this };
|
||||
c: { new (): this };
|
||||
d: { [x: string]: this };
|
||||
e: { f(x: this): this };
|
||||
}
|
||||
|
||||
class C2 {
|
||||
static x: this;
|
||||
static y = <this>undefined;
|
||||
static foo(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
namespace N1 {
|
||||
export var x: this;
|
||||
export var y = this;
|
||||
}
|
||||
|
||||
class C3 {
|
||||
x1 = {
|
||||
g(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
f() {
|
||||
function g(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
let x2 = {
|
||||
h(x: this): this {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
tests/cases/conformance/types/thisType/thisTypeInClasses.ts
Normal file
50
tests/cases/conformance/types/thisType/thisTypeInClasses.ts
Normal file
@ -0,0 +1,50 @@
|
||||
class C1 {
|
||||
x: this;
|
||||
f(x: this): this { return undefined; }
|
||||
constructor(x: this) { }
|
||||
}
|
||||
|
||||
class C2 {
|
||||
[x: string]: this;
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
x: T;
|
||||
y: this;
|
||||
}
|
||||
|
||||
class C3 {
|
||||
a: this[];
|
||||
b: [this, this];
|
||||
c: this | Date;
|
||||
d: this & Date;
|
||||
e: (((this)));
|
||||
f: (x: this) => this;
|
||||
g: new (x: this) => this;
|
||||
h: Foo<this>;
|
||||
i: Foo<this | (() => this)>;
|
||||
j: (x: any) => x is this;
|
||||
}
|
||||
|
||||
declare class C4 {
|
||||
x: this;
|
||||
f(x: this): this;
|
||||
}
|
||||
|
||||
class C5 {
|
||||
foo() {
|
||||
let f1 = (x: this): this => this;
|
||||
let f2 = (x: this) => this;
|
||||
let f3 = (x: this) => (y: this) => this;
|
||||
let f4 = (x: this) => {
|
||||
let g = (y: this) => {
|
||||
return () => this;
|
||||
}
|
||||
return g(this);
|
||||
}
|
||||
}
|
||||
bar() {
|
||||
let x1 = <this>undefined;
|
||||
let x2 = undefined as this;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
interface I1 {
|
||||
x: this;
|
||||
f(x: this): this;
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
(x: this): this;
|
||||
new (x: this): this;
|
||||
[x: string]: this;
|
||||
}
|
||||
|
||||
interface Foo<T> {
|
||||
x: T;
|
||||
y: this;
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
a: this[];
|
||||
b: [this, this];
|
||||
c: this | Date;
|
||||
d: this & Date;
|
||||
e: (((this)));
|
||||
f: (x: this) => this;
|
||||
g: new (x: this) => this;
|
||||
h: Foo<this>;
|
||||
i: Foo<this | (() => this)>;
|
||||
j: (x: any) => x is this;
|
||||
}
|
||||
39
tests/cases/conformance/types/thisType/typeRelationships.ts
Normal file
39
tests/cases/conformance/types/thisType/typeRelationships.ts
Normal file
@ -0,0 +1,39 @@
|
||||
class C {
|
||||
self = this;
|
||||
c = new C();
|
||||
foo() {
|
||||
return this;
|
||||
}
|
||||
f1() {
|
||||
this.c = this.self;
|
||||
this.self = this.c; // Error
|
||||
}
|
||||
f2() {
|
||||
var a: C[];
|
||||
var a = [this, this.c]; // C[] since this is subtype of C
|
||||
var b: this[];
|
||||
var b = [this, this.self, null, undefined];
|
||||
}
|
||||
f3(b: boolean) {
|
||||
return b ? this.c : this.self; // Should be C
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
self1 = this;
|
||||
self2 = this.self;
|
||||
self3 = this.foo();
|
||||
d = new D();
|
||||
bar() {
|
||||
this.self = this.self1;
|
||||
this.self = this.self2;
|
||||
this.self = this.self3;
|
||||
this.self1 = this.self;
|
||||
this.self2 = this.self;
|
||||
this.self3 = this.self;
|
||||
this.d = this.self;
|
||||
this.d = this.c; // Error
|
||||
this.self = this.d; // Error
|
||||
this.c = this.d;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user