mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Adding contextual typing test
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
//// [contextualThisType.ts]
|
||||
interface X {
|
||||
a: (p: this) => this;
|
||||
}
|
||||
|
||||
interface Y extends X {
|
||||
}
|
||||
|
||||
var x: Y = {
|
||||
a(p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
var y = x.a(x);
|
||||
|
||||
|
||||
//// [contextualThisType.js]
|
||||
var x = {
|
||||
a: function (p) {
|
||||
return p;
|
||||
}
|
||||
};
|
||||
var y = x.a(x);
|
||||
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/conformance/types/thisType/contextualThisType.ts ===
|
||||
interface X {
|
||||
>X : Symbol(X, Decl(contextualThisType.ts, 0, 0))
|
||||
|
||||
a: (p: this) => this;
|
||||
>a : Symbol(a, Decl(contextualThisType.ts, 0, 13))
|
||||
>p : Symbol(p, Decl(contextualThisType.ts, 1, 8))
|
||||
}
|
||||
|
||||
interface Y extends X {
|
||||
>Y : Symbol(Y, Decl(contextualThisType.ts, 2, 1))
|
||||
>X : Symbol(X, Decl(contextualThisType.ts, 0, 0))
|
||||
}
|
||||
|
||||
var x: Y = {
|
||||
>x : Symbol(x, Decl(contextualThisType.ts, 7, 3))
|
||||
>Y : Symbol(Y, Decl(contextualThisType.ts, 2, 1))
|
||||
|
||||
a(p) {
|
||||
>a : Symbol(a, Decl(contextualThisType.ts, 7, 12))
|
||||
>p : Symbol(p, Decl(contextualThisType.ts, 8, 6))
|
||||
|
||||
return p;
|
||||
>p : Symbol(p, Decl(contextualThisType.ts, 8, 6))
|
||||
}
|
||||
}
|
||||
|
||||
var y = x.a(x);
|
||||
>y : Symbol(y, Decl(contextualThisType.ts, 13, 3))
|
||||
>x.a : Symbol(X.a, Decl(contextualThisType.ts, 0, 13))
|
||||
>x : Symbol(x, Decl(contextualThisType.ts, 7, 3))
|
||||
>a : Symbol(X.a, Decl(contextualThisType.ts, 0, 13))
|
||||
>x : Symbol(x, Decl(contextualThisType.ts, 7, 3))
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
=== tests/cases/conformance/types/thisType/contextualThisType.ts ===
|
||||
interface X {
|
||||
>X : X
|
||||
|
||||
a: (p: this) => this;
|
||||
>a : (p: this) => this
|
||||
>p : this
|
||||
}
|
||||
|
||||
interface Y extends X {
|
||||
>Y : Y
|
||||
>X : X
|
||||
}
|
||||
|
||||
var x: Y = {
|
||||
>x : Y
|
||||
>Y : Y
|
||||
>{ a(p) { return p; }} : { a(p: Y): Y; }
|
||||
|
||||
a(p) {
|
||||
>a : (p: Y) => Y
|
||||
>p : Y
|
||||
|
||||
return p;
|
||||
>p : Y
|
||||
}
|
||||
}
|
||||
|
||||
var y = x.a(x);
|
||||
>y : Y
|
||||
>x.a(x) : Y
|
||||
>x.a : (p: Y) => Y
|
||||
>x : Y
|
||||
>a : (p: Y) => Y
|
||||
>x : Y
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
interface X {
|
||||
a: (p: this) => this;
|
||||
}
|
||||
|
||||
interface Y extends X {
|
||||
}
|
||||
|
||||
var x: Y = {
|
||||
a(p) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
var y = x.a(x);
|
||||
Reference in New Issue
Block a user