Skip to content

Commit ff2cfd2

Browse files
committed
Update test
1 parent 993397b commit ff2cfd2

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @declaration: true
2+
// @strictNullChecks: true
23
// @noImplicitAny: true
34
// @noImplicitThis: true
45
// @target: es5
@@ -34,15 +35,19 @@ let obj1 = {
3435
type Point = {
3536
x: number;
3637
y: number;
37-
moveBy(dx: number, dy: number): void;
38+
z?: number;
39+
moveBy(dx: number, dy: number, dz?: number): void;
3840
}
3941

4042
let p1: Point = {
4143
x: 10,
4244
y: 20,
43-
moveBy(dx, dy) {
45+
moveBy(dx, dy, dz) {
4446
this.x += dx;
4547
this.y += dy;
48+
if (this.z && dz) {
49+
this.z += dz;
50+
}
4651
}
4752
};
4853

@@ -51,9 +56,12 @@ declare function f1(p: Point): void;
5156
f1({
5257
x: 10,
5358
y: 20,
54-
moveBy(dx, dy) {
59+
moveBy(dx, dy, dz) {
5560
this.x += dx;
5661
this.y += dy;
62+
if (this.z && dz) {
63+
this.z += dz;
64+
}
5765
}
5866
});
5967

@@ -97,6 +105,51 @@ let x2 = makeObject2({
97105
}
98106
});
99107

108+
// Check pattern similar to Object.defineProperty and Object.defineProperties
109+
110+
type PropDesc<T> = {
111+
value?: T;
112+
get?(): T;
113+
set?(value: T): void;
114+
}
115+
116+
type PropDescMap<T> = {
117+
[K in keyof T]: PropDesc<T[K]>;
118+
}
119+
120+
declare function defineProp<T, K extends string, U>(obj: T, name: K, desc: PropDesc<U> & ThisType<T>): T & Record<K, U>;
121+
122+
declare function defineProps<T, U>(obj: T, descs: PropDescMap<U> & ThisType<T>): T & U;
123+
124+
let p10 = defineProp(p1, "foo", { value: 42 });
125+
p10.foo = p10.foo + 1;
126+
127+
let p11 = defineProp(p1, "bar", {
128+
get() {
129+
return this.x;
130+
},
131+
set(value: number) {
132+
this.x = value;
133+
}
134+
});
135+
p11.bar = p11.bar + 1;
136+
137+
let p12 = defineProps(p1, {
138+
foo: {
139+
value: 42
140+
},
141+
bar: {
142+
get(): number {
143+
return this.x;
144+
},
145+
set(value: number) {
146+
this.x = value;
147+
}
148+
}
149+
});
150+
p12.foo = p12.foo + 1;
151+
p12.bar = p12.bar + 1;
152+
100153
// Proof of concept for typing of Vue.js
101154

102155
type Accessors<T> = { [K in keyof T]: (() => T[K]) | Computed<T[K]> };

0 commit comments

Comments
 (0)