1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
// @strict: true
// Repro from #43411
interface IProperties {
foo?: {
aaa: string
bbb: string
}
}
function init(properties: IProperties) {
if (properties.foo) {
type FooOK = typeof properties.foo;
properties.foo; // type is { aaa: string; bbb: string; }
for (const x of [1, 2, 3]) {
properties.foo; // type is { aaa: string; bbb: string; }
type FooOrUndefined = typeof properties.foo; // type should be { aaa: string; bbb: string; }
}
}
}
interface DeepOptional {
a?: {
b?: {
c?: string
}
}
}
function init2(foo: DeepOptional) {
if (foo.a) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
for(const _ of [1]) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
if (foo.a.b) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
for(const _ of [1]) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
if (foo.a.b.c) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
for(const _ of [1]) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
}
}
}
}
}
}
}
// Repro from #48289
type Fish = { type: 'fish', hasFins: true }
type Dog = { type: 'dog', saysWoof: true }
type Pet = Fish | Dog;
function handleDogBroken<PetType extends Pet>(pet: PetType) {
if(pet.type === 'dog') {
const _okay1 = pet.saysWoof;
const _okay2: typeof pet.saysWoof = pet.saysWoof;
}
}
function handleDogWorking(pet: Pet) {
if(pet.type === 'dog') {
const _okay1 = pet.saysWoof;
const _okay2: typeof pet.saysWoof = pet.saysWoof;
}
}
|