TypeScript/tests/baselines/reference/narrowingOfQualifiedNames.errors.txt
Zzzen 756392c1f5
support QualifiedName when narrowing inside loops (#43592)
* support QualifiedName when narrowing inside loops

* add test

* narrow more qualified names

* handle `undefined` of `getFlowCacheKey `

* update comments in test
2021-05-21 10:36:54 -07:00

74 lines
2.4 KiB
Plaintext

tests/cases/compiler/narrowingOfQualifiedNames.ts(33,25): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/narrowingOfQualifiedNames.ts(38,29): error TS2532: Object is possibly 'undefined'.
==== tests/cases/compiler/narrowingOfQualifiedNames.ts (2 errors) ====
// 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;
~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
for(const _ of [1]) {
type A = typeof foo.a;
type B = typeof foo.a.b;
type C = typeof foo.a.b.c;
~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
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;
}
}
}
}
}
}
}