File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
tests/cases/conformance/controlFlow Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -161,3 +161,80 @@ function f01(x: unknown) {
161161 x ;
162162 }
163163}
164+
165+ type Thing = { foo : number , bar ( ) : number } ;
166+
167+ function f10 ( o : Thing | undefined , value : number ) {
168+ if ( o ?. foo === value ) {
169+ o ;
170+ o . foo ;
171+ }
172+ if ( o ?. [ "foo" ] === value ) {
173+ o ;
174+ o [ "foo" ] ;
175+ }
176+ if ( o ?. bar ( ) === value ) {
177+ o ;
178+ o . bar ;
179+ }
180+ }
181+
182+ function f11 ( o : Thing | null , value : number ) {
183+ if ( o ?. foo === value ) {
184+ o ;
185+ o . foo ;
186+ }
187+ if ( o ?. [ "foo" ] === value ) {
188+ o ;
189+ o [ "foo" ] ;
190+ }
191+ if ( o ?. bar ( ) === value ) {
192+ o ;
193+ o . bar ;
194+ }
195+ }
196+
197+ function f12 ( o : Thing | undefined , value : number | undefined ) {
198+ if ( o ?. foo === value ) {
199+ o ;
200+ o . foo ; // Error
201+ }
202+ if ( o ?. [ "foo" ] === value ) {
203+ o ;
204+ o [ "foo" ] ; // Error
205+ }
206+ if ( o ?. bar ( ) === value ) {
207+ o ;
208+ o . bar ; // Error
209+ }
210+ }
211+
212+ function f13 ( o : Thing | undefined ) {
213+ if ( o ?. foo !== undefined ) {
214+ o ;
215+ o . foo ;
216+ }
217+ if ( o ?. [ "foo" ] !== undefined ) {
218+ o ;
219+ o [ "foo" ] ;
220+ }
221+ if ( o ?. bar ( ) !== undefined ) {
222+ o ;
223+ o . bar ;
224+ }
225+ }
226+
227+ function f14 ( o : Thing | null ) {
228+ if ( o ?. foo !== undefined ) {
229+ o ;
230+ o . foo ;
231+ }
232+ if ( o ?. [ "foo" ] !== undefined ) {
233+ o ;
234+ o [ "foo" ] ;
235+ }
236+ if ( o ?. bar ( ) !== undefined ) {
237+ o ;
238+ o . bar ;
239+ }
240+ }
You can’t perform that action at this time.
0 commit comments