Skip to content

Commit 7d9924d

Browse files
committed
Accept new baselines
1 parent a992a68 commit 7d9924d

File tree

4 files changed

+726
-0
lines changed

4 files changed

+726
-0
lines changed

tests/baselines/reference/unknownControlFlow.errors.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,105 @@ tests/cases/conformance/types/unknown/unknownControlFlow.ts(293,5): error TS2345
316316
type NullableFoo = Foo | undefined;
317317

318318
type Bar<T extends NullableFoo> = NonNullable<T>[string];
319+
320+
// Generics and intersections with {}
321+
322+
function fx0<T>(value: T & ({} | null)) {
323+
if (value === 42) {
324+
value; // T & {}
325+
}
326+
else {
327+
value; // T & ({} | null)
328+
}
329+
}
330+
331+
function fx1<T extends unknown>(value: T & ({} | null)) {
332+
if (value === 42) {
333+
value; // T & {}
334+
}
335+
else {
336+
value; // T & ({} | null)
337+
}
338+
}
339+
340+
function fx2<T extends {}>(value: T & ({} | null)) {
341+
if (value === 42) {
342+
value; // T & {}
343+
}
344+
else {
345+
value; // T & ({} | null)
346+
}
347+
}
348+
349+
function fx3<T extends {} | undefined>(value: T & ({} | null)) {
350+
if (value === 42) {
351+
value; // T & {}
352+
}
353+
else {
354+
value; // T & ({} | null)
355+
}
356+
}
357+
358+
function fx4<T extends {} | null>(value: T & ({} | null)) {
359+
if (value === 42) {
360+
value; // T & {}
361+
}
362+
else {
363+
value; // T & ({} | null)
364+
}
365+
}
366+
367+
function fx5<T extends {} | null | undefined>(value: T & ({} | null)) {
368+
if (value === 42) {
369+
value; // T & {}
370+
}
371+
else {
372+
value; // T & ({} | null)
373+
}
374+
}
375+
376+
// Double-equals narrowing
377+
378+
function fx10(x: string | number, y: number) {
379+
if (x == y) {
380+
x; // string | number
381+
}
382+
else {
383+
x; // string | number
384+
}
385+
if (x != y) {
386+
x; // string | number
387+
}
388+
else {
389+
x; // string | number
390+
}
391+
}
392+
393+
// Repros from #50706
394+
395+
function SendBlob(encoding: unknown) {
396+
if (encoding !== undefined && encoding !== 'utf8') {
397+
throw new Error('encoding');
398+
}
399+
encoding;
400+
};
401+
402+
function doSomething1<T extends unknown>(value: T): T {
403+
if (value === undefined) {
404+
return value;
405+
}
406+
if (value === 42) {
407+
throw Error('Meaning of life value');
408+
}
409+
return value;
410+
}
411+
412+
function doSomething2(value: unknown): void {
413+
if (value === undefined) {
414+
return;
415+
}
416+
if (value === 42) {
417+
value;
418+
}
419+
}
319420

tests/baselines/reference/unknownControlFlow.js

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,107 @@ type Foo = { [key: string]: unknown };
299299
type NullableFoo = Foo | undefined;
300300

301301
type Bar<T extends NullableFoo> = NonNullable<T>[string];
302+
303+
// Generics and intersections with {}
304+
305+
function fx0<T>(value: T & ({} | null)) {
306+
if (value === 42) {
307+
value; // T & {}
308+
}
309+
else {
310+
value; // T & ({} | null)
311+
}
312+
}
313+
314+
function fx1<T extends unknown>(value: T & ({} | null)) {
315+
if (value === 42) {
316+
value; // T & {}
317+
}
318+
else {
319+
value; // T & ({} | null)
320+
}
321+
}
322+
323+
function fx2<T extends {}>(value: T & ({} | null)) {
324+
if (value === 42) {
325+
value; // T & {}
326+
}
327+
else {
328+
value; // T & ({} | null)
329+
}
330+
}
331+
332+
function fx3<T extends {} | undefined>(value: T & ({} | null)) {
333+
if (value === 42) {
334+
value; // T & {}
335+
}
336+
else {
337+
value; // T & ({} | null)
338+
}
339+
}
340+
341+
function fx4<T extends {} | null>(value: T & ({} | null)) {
342+
if (value === 42) {
343+
value; // T & {}
344+
}
345+
else {
346+
value; // T & ({} | null)
347+
}
348+
}
349+
350+
function fx5<T extends {} | null | undefined>(value: T & ({} | null)) {
351+
if (value === 42) {
352+
value; // T & {}
353+
}
354+
else {
355+
value; // T & ({} | null)
356+
}
357+
}
358+
359+
// Double-equals narrowing
360+
361+
function fx10(x: string | number, y: number) {
362+
if (x == y) {
363+
x; // string | number
364+
}
365+
else {
366+
x; // string | number
367+
}
368+
if (x != y) {
369+
x; // string | number
370+
}
371+
else {
372+
x; // string | number
373+
}
374+
}
375+
376+
// Repros from #50706
377+
378+
function SendBlob(encoding: unknown) {
379+
if (encoding !== undefined && encoding !== 'utf8') {
380+
throw new Error('encoding');
381+
}
382+
encoding;
383+
};
384+
385+
function doSomething1<T extends unknown>(value: T): T {
386+
if (value === undefined) {
387+
return value;
388+
}
389+
if (value === 42) {
390+
throw Error('Meaning of life value');
391+
}
392+
return value;
393+
}
394+
395+
function doSomething2(value: unknown): void {
396+
if (value === undefined) {
397+
return;
398+
}
399+
if (value === 42) {
400+
value;
401+
}
402+
}
302403

303404

304405
//// [unknownControlFlow.js]
@@ -552,6 +653,95 @@ ff1(null, 'foo'); // Error
552653
ff2(null, 'foo'); // Error
553654
ff3(null, 'foo');
554655
ff4(null, 'foo'); // Error
656+
// Generics and intersections with {}
657+
function fx0(value) {
658+
if (value === 42) {
659+
value; // T & {}
660+
}
661+
else {
662+
value; // T & ({} | null)
663+
}
664+
}
665+
function fx1(value) {
666+
if (value === 42) {
667+
value; // T & {}
668+
}
669+
else {
670+
value; // T & ({} | null)
671+
}
672+
}
673+
function fx2(value) {
674+
if (value === 42) {
675+
value; // T & {}
676+
}
677+
else {
678+
value; // T & ({} | null)
679+
}
680+
}
681+
function fx3(value) {
682+
if (value === 42) {
683+
value; // T & {}
684+
}
685+
else {
686+
value; // T & ({} | null)
687+
}
688+
}
689+
function fx4(value) {
690+
if (value === 42) {
691+
value; // T & {}
692+
}
693+
else {
694+
value; // T & ({} | null)
695+
}
696+
}
697+
function fx5(value) {
698+
if (value === 42) {
699+
value; // T & {}
700+
}
701+
else {
702+
value; // T & ({} | null)
703+
}
704+
}
705+
// Double-equals narrowing
706+
function fx10(x, y) {
707+
if (x == y) {
708+
x; // string | number
709+
}
710+
else {
711+
x; // string | number
712+
}
713+
if (x != y) {
714+
x; // string | number
715+
}
716+
else {
717+
x; // string | number
718+
}
719+
}
720+
// Repros from #50706
721+
function SendBlob(encoding) {
722+
if (encoding !== undefined && encoding !== 'utf8') {
723+
throw new Error('encoding');
724+
}
725+
encoding;
726+
}
727+
;
728+
function doSomething1(value) {
729+
if (value === undefined) {
730+
return value;
731+
}
732+
if (value === 42) {
733+
throw Error('Meaning of life value');
734+
}
735+
return value;
736+
}
737+
function doSomething2(value) {
738+
if (value === undefined) {
739+
return;
740+
}
741+
if (value === 42) {
742+
value;
743+
}
744+
}
555745

556746

557747
//// [unknownControlFlow.d.ts]
@@ -601,3 +791,13 @@ type Foo = {
601791
};
602792
type NullableFoo = Foo | undefined;
603793
type Bar<T extends NullableFoo> = NonNullable<T>[string];
794+
declare function fx0<T>(value: T & ({} | null)): void;
795+
declare function fx1<T extends unknown>(value: T & ({} | null)): void;
796+
declare function fx2<T extends {}>(value: T & ({} | null)): void;
797+
declare function fx3<T extends {} | undefined>(value: T & ({} | null)): void;
798+
declare function fx4<T extends {} | null>(value: T & ({} | null)): void;
799+
declare function fx5<T extends {} | null | undefined>(value: T & ({} | null)): void;
800+
declare function fx10(x: string | number, y: number): void;
801+
declare function SendBlob(encoding: unknown): void;
802+
declare function doSomething1<T extends unknown>(value: T): T;
803+
declare function doSomething2(value: unknown): void;

0 commit comments

Comments
 (0)