TypeScript: error TS1128: Declaration or statement expected.
The parser found a token where a declaration or statement should start — usually stray braces/parentheses or code outside a function.
error TS1128: Declaration or statement expected.Declaration or statement expected. ts(1128)TS1128 Declaration or statement expectederror TS1109: Expression expected.error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. Meaning
Check for an extra } or ) above the line, missing opening brace, statements placed at the top level of a class body, or a half-pasted snippet. Format with Prettier to reveal mismatched brackets. Also appears when using Flow/JSX syntax in .ts files.
Common causes
- Extra closing brace/parenthesis
- Missing opening brace
- Statement directly inside a class body
- Pasted partial code
- JSX/Flow syntax in a
.tsfile
⚡ Quick fix
- Run Prettier/format to see bracket mismatches
- Remove the stray
}or add the missing{ - Move statements into methods/constructors
Detailed fix by platform
Linux
npx prettier --check src/app.ts
How to diagnose
- Brackets — Balanced?
- Position — Inside class body?
- Syntax — JSX in .ts?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026