Skip to content

Commit b31c414

Browse files
committed
Accept new baselines
1 parent 9d4096f commit b31c414

File tree

3 files changed

+377
-44
lines changed

3 files changed

+377
-44
lines changed

tests/baselines/reference/literalTypeWidening.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ function f5() {
6060
let v4 = c4;
6161
}
6262

63+
declare function widening<T>(x: T): T;
64+
declare function nonWidening<T extends string | number | symbol>(x: T): T;
65+
66+
function f6(cond: boolean) {
67+
let x1 = widening('a');
68+
let x2 = widening(10);
69+
let x3 = widening(cond ? 'a' : 10);
70+
let y1 = nonWidening('a');
71+
let y2 = nonWidening(10);
72+
let y3 = nonWidening(cond ? 'a' : 10);
73+
}
74+
6375
// Repro from #10898
6476

6577
type FAILURE = "FAILURE";
@@ -95,10 +107,33 @@ type TestEvent = "onmouseover" | "onmouseout";
95107

96108
function onMouseOver(): TestEvent { return "onmouseover"; }
97109

98-
let x = onMouseOver();
110+
let x = onMouseOver();
111+
112+
// Repro from #23649
113+
114+
export function Set<K extends string>(...keys: K[]): Record<K, true | undefined> {
115+
const result = {} as Record<K, true | undefined>
116+
keys.forEach(key => result[key] = true)
117+
return result
118+
}
119+
120+
export function keys<K extends string, V>(obj: Record<K, V>): K[] {
121+
return Object.keys(obj) as K[]
122+
}
123+
124+
type Obj = { code: LangCode }
125+
126+
const langCodeSet = Set('fr', 'en', 'es', 'it', 'nl')
127+
export type LangCode = keyof typeof langCodeSet
128+
export const langCodes = keys(langCodeSet)
129+
130+
const arr: Obj[] = langCodes.map(code => ({ code }))
131+
99132

100133
//// [literalTypeWidening.js]
134+
"use strict";
101135
// Widening vs. non-widening literal types
136+
exports.__esModule = true;
102137
function f1() {
103138
var c1 = "hello"; // Widening type "hello"
104139
var v1 = c1; // Type string
@@ -153,6 +188,14 @@ function f5() {
153188
var c4 = "foo";
154189
var v4 = c4;
155190
}
191+
function f6(cond) {
192+
var x1 = widening('a');
193+
var x2 = widening(10);
194+
var x3 = widening(cond ? 'a' : 10);
195+
var y1 = nonWidening('a');
196+
var y2 = nonWidening(10);
197+
var y3 = nonWidening(cond ? 'a' : 10);
198+
}
156199
var FAILURE = "FAILURE";
157200
function doWork() {
158201
return FAILURE;
@@ -172,3 +215,21 @@ if (isSuccess(result)) {
172215
}
173216
function onMouseOver() { return "onmouseover"; }
174217
var x = onMouseOver();
218+
// Repro from #23649
219+
function Set() {
220+
var keys = [];
221+
for (var _i = 0; _i < arguments.length; _i++) {
222+
keys[_i] = arguments[_i];
223+
}
224+
var result = {};
225+
keys.forEach(function (key) { return result[key] = true; });
226+
return result;
227+
}
228+
exports.Set = Set;
229+
function keys(obj) {
230+
return Object.keys(obj);
231+
}
232+
exports.keys = keys;
233+
var langCodeSet = Set('fr', 'en', 'es', 'it', 'nl');
234+
exports.langCodes = keys(langCodeSet);
235+
var arr = exports.langCodes.map(function (code) { return ({ code: code }); });

tests/baselines/reference/literalTypeWidening.symbols

Lines changed: 160 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -197,89 +197,206 @@ function f5() {
197197
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9))
198198
}
199199

200+
declare function widening<T>(x: T): T;
201+
>widening : Symbol(widening, Decl(literalTypeWidening.ts, 59, 1))
202+
>T : Symbol(T, Decl(literalTypeWidening.ts, 61, 26))
203+
>x : Symbol(x, Decl(literalTypeWidening.ts, 61, 29))
204+
>T : Symbol(T, Decl(literalTypeWidening.ts, 61, 26))
205+
>T : Symbol(T, Decl(literalTypeWidening.ts, 61, 26))
206+
207+
declare function nonWidening<T extends string | number | symbol>(x: T): T;
208+
>nonWidening : Symbol(nonWidening, Decl(literalTypeWidening.ts, 61, 38))
209+
>T : Symbol(T, Decl(literalTypeWidening.ts, 62, 29))
210+
>x : Symbol(x, Decl(literalTypeWidening.ts, 62, 65))
211+
>T : Symbol(T, Decl(literalTypeWidening.ts, 62, 29))
212+
>T : Symbol(T, Decl(literalTypeWidening.ts, 62, 29))
213+
214+
function f6(cond: boolean) {
215+
>f6 : Symbol(f6, Decl(literalTypeWidening.ts, 62, 74))
216+
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 64, 12))
217+
218+
let x1 = widening('a');
219+
>x1 : Symbol(x1, Decl(literalTypeWidening.ts, 65, 7))
220+
>widening : Symbol(widening, Decl(literalTypeWidening.ts, 59, 1))
221+
222+
let x2 = widening(10);
223+
>x2 : Symbol(x2, Decl(literalTypeWidening.ts, 66, 7))
224+
>widening : Symbol(widening, Decl(literalTypeWidening.ts, 59, 1))
225+
226+
let x3 = widening(cond ? 'a' : 10);
227+
>x3 : Symbol(x3, Decl(literalTypeWidening.ts, 67, 7))
228+
>widening : Symbol(widening, Decl(literalTypeWidening.ts, 59, 1))
229+
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 64, 12))
230+
231+
let y1 = nonWidening('a');
232+
>y1 : Symbol(y1, Decl(literalTypeWidening.ts, 68, 7))
233+
>nonWidening : Symbol(nonWidening, Decl(literalTypeWidening.ts, 61, 38))
234+
235+
let y2 = nonWidening(10);
236+
>y2 : Symbol(y2, Decl(literalTypeWidening.ts, 69, 7))
237+
>nonWidening : Symbol(nonWidening, Decl(literalTypeWidening.ts, 61, 38))
238+
239+
let y3 = nonWidening(cond ? 'a' : 10);
240+
>y3 : Symbol(y3, Decl(literalTypeWidening.ts, 70, 7))
241+
>nonWidening : Symbol(nonWidening, Decl(literalTypeWidening.ts, 61, 38))
242+
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 64, 12))
243+
}
244+
200245
// Repro from #10898
201246

202247
type FAILURE = "FAILURE";
203-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
248+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
204249

205250
const FAILURE = "FAILURE";
206-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
251+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
207252

208253
type Result<T> = T | FAILURE;
209-
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
210-
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
211-
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
212-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
254+
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 76, 26))
255+
>T : Symbol(T, Decl(literalTypeWidening.ts, 78, 12))
256+
>T : Symbol(T, Decl(literalTypeWidening.ts, 78, 12))
257+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
213258

214259
function doWork<T>(): Result<T> {
215-
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
216-
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
217-
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
218-
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
260+
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 78, 29))
261+
>T : Symbol(T, Decl(literalTypeWidening.ts, 80, 16))
262+
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 76, 26))
263+
>T : Symbol(T, Decl(literalTypeWidening.ts, 80, 16))
219264

220265
return FAILURE;
221-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
266+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
222267
}
223268

224269
function isSuccess<T>(result: Result<T>): result is T {
225-
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
226-
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
227-
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
228-
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
229-
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
230-
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
231-
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
270+
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 82, 1))
271+
>T : Symbol(T, Decl(literalTypeWidening.ts, 84, 19))
272+
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 22))
273+
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 76, 26))
274+
>T : Symbol(T, Decl(literalTypeWidening.ts, 84, 19))
275+
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 22))
276+
>T : Symbol(T, Decl(literalTypeWidening.ts, 84, 19))
232277

233278
return !isFailure(result);
234-
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
235-
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
279+
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 86, 1))
280+
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 22))
236281
}
237282

238283
function isFailure<T>(result: Result<T>): result is FAILURE {
239-
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
240-
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
241-
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
242-
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
243-
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
244-
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
245-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
284+
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 86, 1))
285+
>T : Symbol(T, Decl(literalTypeWidening.ts, 88, 19))
286+
>result : Symbol(result, Decl(literalTypeWidening.ts, 88, 22))
287+
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 76, 26))
288+
>T : Symbol(T, Decl(literalTypeWidening.ts, 88, 19))
289+
>result : Symbol(result, Decl(literalTypeWidening.ts, 88, 22))
290+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
246291

247292
return result === FAILURE;
248-
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
249-
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
293+
>result : Symbol(result, Decl(literalTypeWidening.ts, 88, 22))
294+
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 71, 1), Decl(literalTypeWidening.ts, 76, 5))
250295
}
251296

252297
function increment(x: number): number {
253-
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
254-
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
298+
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 90, 1))
299+
>x : Symbol(x, Decl(literalTypeWidening.ts, 92, 19))
255300

256301
return x + 1;
257-
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
302+
>x : Symbol(x, Decl(literalTypeWidening.ts, 92, 19))
258303
}
259304

260305
let result = doWork<number>();
261-
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
262-
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
306+
>result : Symbol(result, Decl(literalTypeWidening.ts, 96, 3))
307+
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 78, 29))
263308

264309
if (isSuccess(result)) {
265-
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
266-
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
310+
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 82, 1))
311+
>result : Symbol(result, Decl(literalTypeWidening.ts, 96, 3))
267312

268313
increment(result);
269-
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
270-
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
314+
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 90, 1))
315+
>result : Symbol(result, Decl(literalTypeWidening.ts, 96, 3))
271316
}
272317

273318
// Repro from #10898
274319

275320
type TestEvent = "onmouseover" | "onmouseout";
276-
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
321+
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 100, 1))
277322

278323
function onMouseOver(): TestEvent { return "onmouseover"; }
279-
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))
280-
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
324+
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 104, 46))
325+
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 100, 1))
281326

282327
let x = onMouseOver();
283-
>x : Symbol(x, Decl(literalTypeWidening.ts, 96, 3))
284-
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))
328+
>x : Symbol(x, Decl(literalTypeWidening.ts, 108, 3))
329+
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 104, 46))
330+
331+
// Repro from #23649
332+
333+
export function Set<K extends string>(...keys: K[]): Record<K, true | undefined> {
334+
>Set : Symbol(Set, Decl(literalTypeWidening.ts, 108, 22))
335+
>K : Symbol(K, Decl(literalTypeWidening.ts, 112, 20))
336+
>keys : Symbol(keys, Decl(literalTypeWidening.ts, 112, 38))
337+
>K : Symbol(K, Decl(literalTypeWidening.ts, 112, 20))
338+
>Record : Symbol(Record, Decl(lib.d.ts, --, --))
339+
>K : Symbol(K, Decl(literalTypeWidening.ts, 112, 20))
340+
341+
const result = {} as Record<K, true | undefined>
342+
>result : Symbol(result, Decl(literalTypeWidening.ts, 113, 7))
343+
>Record : Symbol(Record, Decl(lib.d.ts, --, --))
344+
>K : Symbol(K, Decl(literalTypeWidening.ts, 112, 20))
345+
346+
keys.forEach(key => result[key] = true)
347+
>keys.forEach : Symbol(Array.forEach, Decl(lib.d.ts, --, --))
348+
>keys : Symbol(keys, Decl(literalTypeWidening.ts, 112, 38))
349+
>forEach : Symbol(Array.forEach, Decl(lib.d.ts, --, --))
350+
>key : Symbol(key, Decl(literalTypeWidening.ts, 114, 15))
351+
>result : Symbol(result, Decl(literalTypeWidening.ts, 113, 7))
352+
>key : Symbol(key, Decl(literalTypeWidening.ts, 114, 15))
353+
354+
return result
355+
>result : Symbol(result, Decl(literalTypeWidening.ts, 113, 7))
356+
}
357+
358+
export function keys<K extends string, V>(obj: Record<K, V>): K[] {
359+
>keys : Symbol(keys, Decl(literalTypeWidening.ts, 116, 1))
360+
>K : Symbol(K, Decl(literalTypeWidening.ts, 118, 21))
361+
>V : Symbol(V, Decl(literalTypeWidening.ts, 118, 38))
362+
>obj : Symbol(obj, Decl(literalTypeWidening.ts, 118, 42))
363+
>Record : Symbol(Record, Decl(lib.d.ts, --, --))
364+
>K : Symbol(K, Decl(literalTypeWidening.ts, 118, 21))
365+
>V : Symbol(V, Decl(literalTypeWidening.ts, 118, 38))
366+
>K : Symbol(K, Decl(literalTypeWidening.ts, 118, 21))
367+
368+
return Object.keys(obj) as K[]
369+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.d.ts, --, --))
370+
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
371+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.d.ts, --, --))
372+
>obj : Symbol(obj, Decl(literalTypeWidening.ts, 118, 42))
373+
>K : Symbol(K, Decl(literalTypeWidening.ts, 118, 21))
374+
}
375+
376+
type Obj = { code: LangCode }
377+
>Obj : Symbol(Obj, Decl(literalTypeWidening.ts, 120, 1))
378+
>code : Symbol(code, Decl(literalTypeWidening.ts, 122, 12))
379+
>LangCode : Symbol(LangCode, Decl(literalTypeWidening.ts, 124, 53))
380+
381+
const langCodeSet = Set('fr', 'en', 'es', 'it', 'nl')
382+
>langCodeSet : Symbol(langCodeSet, Decl(literalTypeWidening.ts, 124, 5))
383+
>Set : Symbol(Set, Decl(literalTypeWidening.ts, 108, 22))
384+
385+
export type LangCode = keyof typeof langCodeSet
386+
>LangCode : Symbol(LangCode, Decl(literalTypeWidening.ts, 124, 53))
387+
>langCodeSet : Symbol(langCodeSet, Decl(literalTypeWidening.ts, 124, 5))
388+
389+
export const langCodes = keys(langCodeSet)
390+
>langCodes : Symbol(langCodes, Decl(literalTypeWidening.ts, 126, 12))
391+
>keys : Symbol(keys, Decl(literalTypeWidening.ts, 116, 1))
392+
>langCodeSet : Symbol(langCodeSet, Decl(literalTypeWidening.ts, 124, 5))
393+
394+
const arr: Obj[] = langCodes.map(code => ({ code }))
395+
>arr : Symbol(arr, Decl(literalTypeWidening.ts, 128, 5))
396+
>Obj : Symbol(Obj, Decl(literalTypeWidening.ts, 120, 1))
397+
>langCodes.map : Symbol(Array.map, Decl(lib.d.ts, --, --))
398+
>langCodes : Symbol(langCodes, Decl(literalTypeWidening.ts, 126, 12))
399+
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
400+
>code : Symbol(code, Decl(literalTypeWidening.ts, 128, 33))
401+
>code : Symbol(code, Decl(literalTypeWidening.ts, 128, 43))
285402

0 commit comments

Comments
 (0)