Skip to content

Commit 0ac92b4

Browse files
committed
Add tests
1 parent fa02c80 commit 0ac92b4

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

tests/cases/conformance/types/thisType/thisTypeInObjectLiterals2.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// @declaration: true
2-
// @strictNullChecks: true
3-
// @noImplicitAny: true
4-
// @noImplicitThis: true
2+
// @strict: true
53
// @target: es5
64

75
// In methods of an object literal with no contextual type, 'this' has the type
@@ -51,6 +49,42 @@ let p1: Point = {
5149
}
5250
};
5351

52+
let p2: Point | null = {
53+
x: 10,
54+
y: 20,
55+
moveBy(dx, dy, dz) {
56+
this.x += dx;
57+
this.y += dy;
58+
if (this.z && dz) {
59+
this.z += dz;
60+
}
61+
}
62+
};
63+
64+
let p3: Point | undefined = {
65+
x: 10,
66+
y: 20,
67+
moveBy(dx, dy, dz) {
68+
this.x += dx;
69+
this.y += dy;
70+
if (this.z && dz) {
71+
this.z += dz;
72+
}
73+
}
74+
};
75+
76+
let p4: Point | null | undefined = {
77+
x: 10,
78+
y: 20,
79+
moveBy(dx, dy, dz) {
80+
this.x += dx;
81+
this.y += dy;
82+
if (this.z && dz) {
83+
this.z += dz;
84+
}
85+
}
86+
};
87+
5488
declare function f1(p: Point): void;
5589

5690
f1({
@@ -65,6 +99,20 @@ f1({
6599
}
66100
});
67101

102+
declare function f2(p: Point | null | undefined): void;
103+
104+
f2({
105+
x: 10,
106+
y: 20,
107+
moveBy(dx, dy, dz) {
108+
this.x += dx;
109+
this.y += dy;
110+
if (this.z && dz) {
111+
this.z += dz;
112+
}
113+
}
114+
});
115+
68116
// In methods of an object literal with a contextual type that includes some
69117
// ThisType<T>, 'this' is of type T.
70118

0 commit comments

Comments
 (0)