Skip to content

Commit c87c124

Browse files
committed
Accept new baselines
1 parent ff2cfd2 commit c87c124

File tree

3 files changed

+715
-192
lines changed

3 files changed

+715
-192
lines changed

tests/baselines/reference/thisTypeInObjectLiterals2.js

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ let obj1 = {
3131
type Point = {
3232
x: number;
3333
y: number;
34-
moveBy(dx: number, dy: number): void;
34+
z?: number;
35+
moveBy(dx: number, dy: number, dz?: number): void;
3536
}
3637

3738
let p1: Point = {
3839
x: 10,
3940
y: 20,
40-
moveBy(dx, dy) {
41+
moveBy(dx, dy, dz) {
4142
this.x += dx;
4243
this.y += dy;
44+
if (this.z && dz) {
45+
this.z += dz;
46+
}
4347
}
4448
};
4549

@@ -48,9 +52,12 @@ declare function f1(p: Point): void;
4852
f1({
4953
x: 10,
5054
y: 20,
51-
moveBy(dx, dy) {
55+
moveBy(dx, dy, dz) {
5256
this.x += dx;
5357
this.y += dy;
58+
if (this.z && dz) {
59+
this.z += dz;
60+
}
5461
}
5562
});
5663

@@ -94,6 +101,51 @@ let x2 = makeObject2({
94101
}
95102
});
96103

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

99151
type Accessors<T> = { [K in keyof T]: (() => T[K]) | Computed<T[K]> };
@@ -168,17 +220,23 @@ var obj1 = {
168220
var p1 = {
169221
x: 10,
170222
y: 20,
171-
moveBy: function (dx, dy) {
223+
moveBy: function (dx, dy, dz) {
172224
this.x += dx;
173225
this.y += dy;
226+
if (this.z && dz) {
227+
this.z += dz;
228+
}
174229
}
175230
};
176231
f1({
177232
x: 10,
178233
y: 20,
179-
moveBy: function (dx, dy) {
234+
moveBy: function (dx, dy, dz) {
180235
this.x += dx;
181236
this.y += dy;
237+
if (this.z && dz) {
238+
this.z += dz;
239+
}
182240
}
183241
});
184242
var x1 = makeObject({
@@ -199,6 +257,32 @@ var x2 = makeObject2({
199257
}
200258
}
201259
});
260+
var p10 = defineProp(p1, "foo", { value: 42 });
261+
p10.foo = p10.foo + 1;
262+
var p11 = defineProp(p1, "bar", {
263+
get: function () {
264+
return this.x;
265+
},
266+
set: function (value) {
267+
this.x = value;
268+
}
269+
});
270+
p11.bar = p11.bar + 1;
271+
var p12 = defineProps(p1, {
272+
foo: {
273+
value: 42
274+
},
275+
bar: {
276+
get: function () {
277+
return this.x;
278+
},
279+
set: function (value) {
280+
this.x = value;
281+
}
282+
}
283+
});
284+
p12.foo = p12.foo + 1;
285+
p12.bar = p12.bar + 1;
202286
var vue = new Vue({
203287
data: function () { return ({ x: 1, y: 2 }); },
204288
methods: {
@@ -240,7 +324,8 @@ declare let obj1: {
240324
declare type Point = {
241325
x: number;
242326
y: number;
243-
moveBy(dx: number, dy: number): void;
327+
z?: number;
328+
moveBy(dx: number, dy: number, dz?: number): void;
244329
};
245330
declare let p1: Point;
246331
declare function f1(p: Point): void;
@@ -266,6 +351,22 @@ declare let x2: {
266351
} & {
267352
moveBy(dx: number, dy: number): void;
268353
};
354+
declare type PropDesc<T> = {
355+
value?: T;
356+
get?(): T;
357+
set?(value: T): void;
358+
};
359+
declare type PropDescMap<T> = {
360+
[K in keyof T]: PropDesc<T[K]>;
361+
};
362+
declare function defineProp<T, K extends string, U>(obj: T, name: K, desc: PropDesc<U> & ThisType<T>): T & Record<K, U>;
363+
declare function defineProps<T, U>(obj: T, descs: PropDescMap<U> & ThisType<T>): T & U;
364+
declare let p10: Point & Record<"foo", number>;
365+
declare let p11: Point & Record<"bar", number>;
366+
declare let p12: Point & {
367+
foo: number;
368+
bar: number;
369+
};
269370
declare type Accessors<T> = {
270371
[K in keyof T]: (() => T[K]) | Computed<T[K]>;
271372
};

0 commit comments

Comments
 (0)