TypeScript 2695: left side of comma operator is unused in React code
Left side of comma operator is unused and has no side effects.ts(2695)Short answer
In JavaScript a comma between expressions evaluates all of them and keeps only the last, so the left ones are thrown away. TypeScript flags that. In React it nearly always means two JSX elements or two values were joined with a comma where a wrapper or separate expressions were meant.
Fix it fast
1Find out which cause you have
Open the line the editor underlines and look at the comma. Ask whether the thing on its left is something you expected to see in the result.
npx tsc --noEmit2Match what you see, then jump to its fix
- 1
return (<Header />, <Main />) or two elements in one pair of parentheses separated by a commaTwo JSX elements are returned with a comma between themFix - 2
<p>{firstName, lastName}</p> or a prop like value={a, b}Two values are written inside one pair of curly bracesFix - 3
const x = (a, b); or an arrow function body like () => (setOpen(true), count) that was meant to hold two valuesA declaration is wrapped in parentheses, so the comma becomes an operatorFix
- 1
What does the error look like?
Left side of comma operator is unused and has no side effects.ts(2695)
Cause 1 of 3
Two JSX elements are returned with a comma between them
1Check
Only the last operand of a comma expression is returned, so Header is evaluated and dropped. A component also may not return two sibling JSX tags without a wrapper.
grep -rn "return (<" src | grep "/>,"2Fix
Delete the comma and wrap the siblings in a Fragment, or in a div if you need an element.
return (
<>
<Header />
<Main />
</>
);3Verify
Run the type check; the error is gone and both components render.
npx tsc --noEmitConfirmed by react.dev
Cause 2 of 3
Two values are written inside one pair of curly braces
1Check
Curly braces in JSX hold a single JavaScript expression. With a comma inside them, only the value after the last comma is used and the first is evaluated and discarded.
grep -rnE "\{[a-zA-Z_.]+, [a-zA-Z_.]+\}" src --include=*.tsx2Fix
Make it one expression, for example a template string, or use two separate pairs of braces.
<p>{`${firstName} ${lastName}`}</p>
<p>{firstName} {lastName}</p>3Verify
Both names show on the page and tsc is clean.
npx tsc --noEmitConfirmed by developer.mozilla.org
Cause 3 of 3
A declaration is wrapped in parentheses, so the comma becomes an operator
1Check
A comma that separates declarations in const a = 1, b = 2 is not the comma operator. Put the pair in parentheses and it becomes one, and the first value is discarded.
grep -rnE "= \([a-zA-Z_]+, " src --include=*.ts --include=*.tsx2Fix
If you want two values, use an array or object. If you want two separate variables, drop the parentheses.
const pair = [a, b];
const first = a, second = b;3Verify
The variables hold what you expect and the error disappears.
npx tsc --noEmitConfirmed by developer.mozilla.org
How do I stop it coming back?
- Wrap sibling JSX in a Fragment as soon as you add a second root element.
- Run tsc --noEmit or the editor's diagnostics before committing.
- Use an array or an object when a function must return two values.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Parse error: adjacent JSX elements must be wrapped in an enclosing tag
Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag
A component can return only one JSX root, because JSX compiles to one JavaScript object.
3 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fixWeb apps
TypeScript says a JavaScript module implicitly has an any type
Could not find a declaration file for module 'react-materialize'. 'path/to/module-name.js' implicitly has an 'any' type.
TypeScript found the JavaScript file but no types for it, and noImplicitAny turns that into an error.
2 causes, each with a fixWeb apps
TypeScript says a function lacks an ending return statement
A function with a declared return type, such as Promise<string>, shows the red line under the type
TypeScript found a way for your function to reach its closing brace without returning a value, while the declared return type does not allow undefined.
4 causes, each with a fixWeb apps
TypeScript: property does not exist on type IntrinsicAttributes in a React component
Object literal may only specify known properties
TypeScript checks the props you write in JSX against the component's props type.
3 causes, each with a fix