Skip to content

Commit c2b785e

Browse files
committed
add another extra test case
1 parent b549581 commit c2b785e

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

tests/baselines/reference/controlFlowOptionalChain3.errors.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined'.
2+
controlFlowOptionalChain3.tsx(36,31): error TS18048: 'options' is possibly 'undefined'.
23

34

4-
==== controlFlowOptionalChain3.tsx (1 errors) ====
5+
==== controlFlowOptionalChain3.tsx (2 errors) ====
56
/// <reference path="/.lib/react16.d.ts" />
67

78
// https://github.com/microsoft/TypeScript/issues/56482
@@ -37,4 +38,12 @@ controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined
3738
</div>
3839
);
3940
}
41+
42+
function test4(options?: { a?: boolean; b?: boolean }) {
43+
if (options?.a === false || options.b) {
44+
~~~~~~~
45+
!!! error TS18048: 'options' is possibly 'undefined'.
46+
options;
47+
}
48+
}
4049

tests/baselines/reference/controlFlowOptionalChain3.symbols

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,22 @@ function Test3({ foo }: { foo: Foo | undefined }) {
7777
);
7878
}
7979

80+
function test4(options?: { a?: boolean; b?: boolean }) {
81+
>test4 : Symbol(test4, Decl(controlFlowOptionalChain3.tsx, 32, 1))
82+
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
83+
>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
84+
>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))
85+
86+
if (options?.a === false || options.b) {
87+
>options?.a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
88+
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
89+
>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
90+
>options.b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))
91+
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
92+
>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))
93+
94+
options;
95+
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
96+
}
97+
}
98+

tests/baselines/reference/controlFlowOptionalChain3.types

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ function Test3({ foo }: { foo: Foo | undefined }) {
8686
);
8787
}
8888

89+
function test4(options?: { a?: boolean; b?: boolean }) {
90+
>test4 : (options?: { a?: boolean; b?: boolean;}) => void
91+
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
92+
>a : boolean | undefined
93+
>b : boolean | undefined
94+
95+
if (options?.a === false || options.b) {
96+
>options?.a === false || options.b : boolean | undefined
97+
>options?.a === false : boolean
98+
>options?.a : boolean | undefined
99+
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
100+
>a : boolean | undefined
101+
>false : false
102+
>options.b : boolean | undefined
103+
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
104+
>b : boolean | undefined
105+
106+
options;
107+
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
108+
}
109+
}
110+

tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ function Test3({ foo }: { foo: Foo | undefined }) {
3636
</div>
3737
);
3838
}
39+
40+
function test4(options?: { a?: boolean; b?: boolean }) {
41+
if (options?.a === false || options.b) {
42+
options;
43+
}
44+
}

0 commit comments

Comments
 (0)