mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add tests
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
// @declaration: true
|
||||
// @strictNullChecks: true
|
||||
// @noImplicitAny: true
|
||||
// @noImplicitThis: true
|
||||
// @strict: true
|
||||
// @target: es5
|
||||
|
||||
// In methods of an object literal with no contextual type, 'this' has the type
|
||||
@@ -51,6 +49,42 @@ let p1: Point = {
|
||||
}
|
||||
};
|
||||
|
||||
let p2: Point | null = {
|
||||
x: 10,
|
||||
y: 20,
|
||||
moveBy(dx, dy, dz) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
if (this.z && dz) {
|
||||
this.z += dz;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let p3: Point | undefined = {
|
||||
x: 10,
|
||||
y: 20,
|
||||
moveBy(dx, dy, dz) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
if (this.z && dz) {
|
||||
this.z += dz;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let p4: Point | null | undefined = {
|
||||
x: 10,
|
||||
y: 20,
|
||||
moveBy(dx, dy, dz) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
if (this.z && dz) {
|
||||
this.z += dz;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
declare function f1(p: Point): void;
|
||||
|
||||
f1({
|
||||
@@ -65,6 +99,20 @@ f1({
|
||||
}
|
||||
});
|
||||
|
||||
declare function f2(p: Point | null | undefined): void;
|
||||
|
||||
f2({
|
||||
x: 10,
|
||||
y: 20,
|
||||
moveBy(dx, dy, dz) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
if (this.z && dz) {
|
||||
this.z += dz;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// In methods of an object literal with a contextual type that includes some
|
||||
// ThisType<T>, 'this' is of type T.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user