Learn why TypeScript throws TS1005 for missing syntax tokens like semicolons, brackets, and commas, and how to fix syntax errors.
TS1005 is a syntax-level error that fires when the TypeScript parser expects a specific token but finds something else instead. The error message always tells you what it expected — for example, ';' expected, ')' expected, or ',' expected.
This is one of the earliest errors the compiler can catch because it happens during parsing, before TypeScript even begins type checking. If you have a TS1005, nothing else in the file can be reliably analyzed until you fix it.
// The general shape of the error:
// ';' expected.
// ')' expected.
// ',' expected.When you forget a comma or semicolon between properties, the parser gets confused about where one declaration ends and the next begins.
// ❌ Broken
interface UserConfig {
hostname: string
port: number
secure: boolean
timeout: number // missing comma/semicolon isn't the issue here...
retries // ...but forgetting the type annotation is
}
// Error: ':' expected.// ✅ Fixed — add the type annotation
interface UserConfig {
hostname: string
port: number
secure: boolean
timeout: number
retries: number
}A missing closing bracket causes the parser to keep reading, eventually expecting a token that doesn't make sense in context.
// ❌ Broken
function calculateTotal(items: number[]) {
let total = 0
for (const item of items) {
total += item
// missing closing brace for the for loop
return total
}
// Error: '}' expected.// ✅ Fixed — close the for block
function calculateTotal(items: number[]) {
let total = 0
for (const item of items) {
total += item
}
return total
}Sometimes TS1005 appears when you accidentally use syntax from another language or a proposal that TypeScript doesn't yet support.
// ❌ Broken — using a pipe where TypeScript expects something else
function processData(input: string | number,) {
const result = input |> transform
// ^ Error: ';' expected.
}// ✅ Fixed — use a regular function call
function processData(input: string | number) {
const result = transform(input)
}Read the error message carefully. It tells you exactly which token was expected (;, ), }, ,, etc.) and where.
Check the reported line and the lines above it. The real problem is often a few lines before where the error appears, because the parser keeps trying to make sense of the code.
Count your brackets. Use your editor's bracket matching feature to find unclosed {, (, or [ characters. Most editors highlight matching pairs when your cursor is on one.
Look for copy-paste artifacts. TS1005 frequently appears after pasting code that lost a closing bracket or gained an extra opening one.
Fix the first TS1005 error first. A single missing token can cascade into dozens of errors. Fix the earliest one, save, and many others will disappear.
// A single missing brace can cause many errors — fix the root cause
function fetchUsers() {
return fetch("/api/users")
.then((response) => response.json())
.then((data) => {
return data.users
}) // make sure every opening brace has a match
}TS1005 occurs when the TypeScript parser encounters unexpected syntax because a required token is missing. This includes semicolons, commas, colons, parentheses, brackets, and braces. The parser has strict expectations about what comes next at every point in your code, and when those expectations aren't met, it raises TS1005.
Common triggers include forgetting to close a bracket, omitting a type annotation colon, or accidentally deleting punctuation during editing.
The error message itself is your best clue — it says exactly which token was expected. Start at the reported line and work backward. Your editor's bracket-matching and auto-indentation features are invaluable here. If your code suddenly looks mis-indented, that's usually where a bracket went missing.
You can also try commenting out blocks of code to isolate which section contains the syntax error.
The TypeScript parser reads your code left-to-right, top-to-bottom. When a token is missing, the parser doesn't immediately fail — it tries to continue parsing in hopes of recovering. This means it might read several more lines before it encounters something that makes no sense at all. The reported error location is where the parser finally gave up, not where the mistake was made. Always scan the lines above the error for the real culprit.
Get the latest TypeScript tips, tutorials, and course updates delivered straight to your inbox.