- Error
- Reported by the lexer and parser
TS5076
'{0}' and '{1}' operations cannot be mixed without parentheses.
Two operators like `??` and `||` are mixed without parentheses. Add parentheses to say which runs first.
What it means
?? can't be combined directly with || or && in the same expression. The order of evaluation would be ambiguous to a reader, so the grammar requires parentheses around one side. ts-r's parser reports this as a syntax error.
Example
declare const a: string | undefined;
declare const b: boolean;
export const value = a ?? b || "default";
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,22): error TS5076: '??' and '||' operations cannot be mixed without parentheses.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Add parentheses around the part that should run first:
(a ?? b) || "default"ora ?? (b || "default").