Skip to content

Commit 8bb30e2

Browse files
committed
Add another repro
1 parent 9ea8a55 commit 8bb30e2

5 files changed

+153
-0
lines changed

tests/baselines/reference/strictSubtypeAndNarrowing.errors.txt

+20
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,24 @@ tests/cases/compiler/strictSubtypeAndNarrowing.ts(129,26): error TS2322: Type '{
226226
assert(!doesValueAtDeepPathSatisfy(foo, ['value', 'type'], isB));
227227
return foo;
228228
}
229+
230+
// Repro from #53063
231+
232+
interface Free {
233+
premium: false;
234+
}
235+
236+
interface Premium {
237+
premium: true;
238+
}
239+
240+
type Union = { premium: false } | { premium: true };
241+
242+
declare const checkIsPremium: (a: Union) => a is Union & Premium;
243+
244+
const f = (value: Union) => {
245+
if (!checkIsPremium(value)) {
246+
value.premium;
247+
}
248+
};
229249

tests/baselines/reference/strictSubtypeAndNarrowing.js

+25
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ function test2(foo: Foo): {value: {type: 'A'}; a?: number} {
209209
assert(!doesValueAtDeepPathSatisfy(foo, ['value', 'type'], isB));
210210
return foo;
211211
}
212+
213+
// Repro from #53063
214+
215+
interface Free {
216+
premium: false;
217+
}
218+
219+
interface Premium {
220+
premium: true;
221+
}
222+
223+
type Union = { premium: false } | { premium: true };
224+
225+
declare const checkIsPremium: (a: Union) => a is Union & Premium;
226+
227+
const f = (value: Union) => {
228+
if (!checkIsPremium(value)) {
229+
value.premium;
230+
}
231+
};
212232

213233

214234
//// [strictSubtypeAndNarrowing.js]
@@ -341,3 +361,8 @@ function test2(foo) {
341361
assert(!doesValueAtDeepPathSatisfy(foo, ['value', 'type'], isB));
342362
return foo;
343363
}
364+
var f = function (value) {
365+
if (!checkIsPremium(value)) {
366+
value.premium;
367+
}
368+
};

tests/baselines/reference/strictSubtypeAndNarrowing.symbols

+45
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,48 @@ function test2(foo: Foo): {value: {type: 'A'}; a?: number} {
556556
>foo : Symbol(foo, Decl(strictSubtypeAndNarrowing.ts, 206, 15))
557557
}
558558

559+
// Repro from #53063
560+
561+
interface Free {
562+
>Free : Symbol(Free, Decl(strictSubtypeAndNarrowing.ts, 209, 1))
563+
564+
premium: false;
565+
>premium : Symbol(Free.premium, Decl(strictSubtypeAndNarrowing.ts, 213, 16))
566+
}
567+
568+
interface Premium {
569+
>Premium : Symbol(Premium, Decl(strictSubtypeAndNarrowing.ts, 215, 1))
570+
571+
premium: true;
572+
>premium : Symbol(Premium.premium, Decl(strictSubtypeAndNarrowing.ts, 217, 19))
573+
}
574+
575+
type Union = { premium: false } | { premium: true };
576+
>Union : Symbol(Union, Decl(strictSubtypeAndNarrowing.ts, 219, 1))
577+
>premium : Symbol(premium, Decl(strictSubtypeAndNarrowing.ts, 221, 14))
578+
>premium : Symbol(premium, Decl(strictSubtypeAndNarrowing.ts, 221, 35))
579+
580+
declare const checkIsPremium: (a: Union) => a is Union & Premium;
581+
>checkIsPremium : Symbol(checkIsPremium, Decl(strictSubtypeAndNarrowing.ts, 223, 13))
582+
>a : Symbol(a, Decl(strictSubtypeAndNarrowing.ts, 223, 31))
583+
>Union : Symbol(Union, Decl(strictSubtypeAndNarrowing.ts, 219, 1))
584+
>a : Symbol(a, Decl(strictSubtypeAndNarrowing.ts, 223, 31))
585+
>Union : Symbol(Union, Decl(strictSubtypeAndNarrowing.ts, 219, 1))
586+
>Premium : Symbol(Premium, Decl(strictSubtypeAndNarrowing.ts, 215, 1))
587+
588+
const f = (value: Union) => {
589+
>f : Symbol(f, Decl(strictSubtypeAndNarrowing.ts, 225, 5))
590+
>value : Symbol(value, Decl(strictSubtypeAndNarrowing.ts, 225, 11))
591+
>Union : Symbol(Union, Decl(strictSubtypeAndNarrowing.ts, 219, 1))
592+
593+
if (!checkIsPremium(value)) {
594+
>checkIsPremium : Symbol(checkIsPremium, Decl(strictSubtypeAndNarrowing.ts, 223, 13))
595+
>value : Symbol(value, Decl(strictSubtypeAndNarrowing.ts, 225, 11))
596+
597+
value.premium;
598+
>value.premium : Symbol(premium, Decl(strictSubtypeAndNarrowing.ts, 221, 14))
599+
>value : Symbol(value, Decl(strictSubtypeAndNarrowing.ts, 225, 11))
600+
>premium : Symbol(premium, Decl(strictSubtypeAndNarrowing.ts, 221, 14))
601+
}
602+
};
603+

tests/baselines/reference/strictSubtypeAndNarrowing.types

+43
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,46 @@ function test2(foo: Foo): {value: {type: 'A'}; a?: number} {
514514
>foo : { value: { type: "A"; }; a?: number | undefined; }
515515
}
516516

517+
// Repro from #53063
518+
519+
interface Free {
520+
premium: false;
521+
>premium : false
522+
>false : false
523+
}
524+
525+
interface Premium {
526+
premium: true;
527+
>premium : true
528+
>true : true
529+
}
530+
531+
type Union = { premium: false } | { premium: true };
532+
>Union : { premium: false; } | { premium: true; }
533+
>premium : false
534+
>false : false
535+
>premium : true
536+
>true : true
537+
538+
declare const checkIsPremium: (a: Union) => a is Union & Premium;
539+
>checkIsPremium : (a: Union) => a is { premium: true; } & Premium
540+
>a : Union
541+
542+
const f = (value: Union) => {
543+
>f : (value: Union) => void
544+
>(value: Union) => { if (!checkIsPremium(value)) { value.premium; }} : (value: Union) => void
545+
>value : Union
546+
547+
if (!checkIsPremium(value)) {
548+
>!checkIsPremium(value) : boolean
549+
>checkIsPremium(value) : boolean
550+
>checkIsPremium : (a: Union) => a is { premium: true; } & Premium
551+
>value : Union
552+
553+
value.premium;
554+
>value.premium : false
555+
>value : { premium: false; }
556+
>premium : false
557+
}
558+
};
559+

tests/cases/compiler/strictSubtypeAndNarrowing.ts

+20
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,23 @@ function test2(foo: Foo): {value: {type: 'A'}; a?: number} {
210210
assert(!doesValueAtDeepPathSatisfy(foo, ['value', 'type'], isB));
211211
return foo;
212212
}
213+
214+
// Repro from #53063
215+
216+
interface Free {
217+
premium: false;
218+
}
219+
220+
interface Premium {
221+
premium: true;
222+
}
223+
224+
type Union = { premium: false } | { premium: true };
225+
226+
declare const checkIsPremium: (a: Union) => a is Union & Premium;
227+
228+
const f = (value: Union) => {
229+
if (!checkIsPremium(value)) {
230+
value.premium;
231+
}
232+
};

0 commit comments

Comments
 (0)