--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: complexLogicalAndCases.ts --- # Input ```ts // currently do not handle complex computed properties foo && foo[bar as string] && foo[bar as string].baz; foo && foo[1 + 2] && foo[1 + 2].baz; foo && foo[typeof bar] && foo[typeof bar].baz; ``` # Diagnostics ``` complexLogicalAndCases.ts:2:1 lint/complexity/useOptionalChain FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Change to an optional chain. 1 │ // currently do not handle complex computed properties > 2 │ foo && foo[bar as string] && foo[bar as string].baz; │ ^^^^^^^^^^^^^^^^^^^^^^^^^ 3 │ foo && foo[1 + 2] && foo[1 + 2].baz; 4 │ foo && foo[typeof bar] && foo[typeof bar].baz; i Unsafe fix: Change to an optional chain. 1 1 │ // currently do not handle complex computed properties 2 │ - foo·&&·foo[bar·as·string]·&&·foo[bar·as·string].baz; 2 │ + foo?.[bar·as·string]·&&·foo[bar·as·string].baz; 3 3 │ foo && foo[1 + 2] && foo[1 + 2].baz; 4 4 │ foo && foo[typeof bar] && foo[typeof bar].baz; ``` ``` complexLogicalAndCases.ts:3:1 lint/complexity/useOptionalChain FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Change to an optional chain. 1 │ // currently do not handle complex computed properties 2 │ foo && foo[bar as string] && foo[bar as string].baz; > 3 │ foo && foo[1 + 2] && foo[1 + 2].baz; │ ^^^^^^^^^^^^^^^^^ 4 │ foo && foo[typeof bar] && foo[typeof bar].baz; 5 │ i Unsafe fix: Change to an optional chain. 1 1 │ // currently do not handle complex computed properties 2 2 │ foo && foo[bar as string] && foo[bar as string].baz; 3 │ - foo·&&·foo[1·+·2]·&&·foo[1·+·2].baz; 3 │ + foo?.[1·+·2]·&&·foo[1·+·2].baz; 4 4 │ foo && foo[typeof bar] && foo[typeof bar].baz; 5 5 │ ``` ``` complexLogicalAndCases.ts:4:1 lint/complexity/useOptionalChain FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Change to an optional chain. 2 │ foo && foo[bar as string] && foo[bar as string].baz; 3 │ foo && foo[1 + 2] && foo[1 + 2].baz; > 4 │ foo && foo[typeof bar] && foo[typeof bar].baz; │ ^^^^^^^^^^^^^^^^^^^^^^ 5 │ i Unsafe fix: Change to an optional chain. 2 2 │ foo && foo[bar as string] && foo[bar as string].baz; 3 3 │ foo && foo[1 + 2] && foo[1 + 2].baz; 4 │ - foo·&&·foo[typeof·bar]·&&·foo[typeof·bar].baz; 4 │ + foo?.[typeof·bar]·&&·foo[typeof·bar].baz; 5 5 │ ```