mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Adding tests
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user