TypeScript Reference ยท Error Codes Worth Knowing
TypeScript error TS1005: token expected (syntax errors)
TS1005 is TypeScript's generic syntax error: a comma, semicolon, bracket or parenthesis is expected. Learn how to find the real cause, often a line above.
TS1005 is the parser's way of saying that a specific token was required and something else appeared. The message names the missing token: ',' expected., ';' expected., ')' expected., '}' expected., ':' expected., '=>' expected. and so on. It is a syntax error, so it appears before any type checking and usually comes with more errors, because after one mistake the parser has to guess how to continue.
The reported position is where the parser noticed the problem, which is often just after the real mistake. If the line looks right, check the previous line for a missing comma, bracket, or quote.
const xs = [1, 2 3]; // error TS1005: ',' expected.
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
Messages you will see, and what usually causes them:
| Message | Typical cause |
|---|---|
',' expected. |
Missing comma in arrays, objects, parameters, or arguments. |
';' expected. |
Two statements on a line without a separator, or an unfinished expression. |
')' expected. |
Unclosed call or condition, or a missing comma inside the parentheses. |
'}' expected. |
A block or object literal was never closed. |
':' expected. |
Object property without a value, or a ternary missing its else part. |
Identifier expected. |
A reserved word used as a name, or a stray symbol. |
Declaration or statement expected. |
Extra closing brace or text after the end of a block. |
Usage notes
- Fix the first error only, then re-run. Later errors are often side effects of the first.
- Look upward. The parser reports at the first token that cannot continue the construct, which can be after the end of the broken line.
- Unbalanced quotes and backticks turn the rest of the file into one string and produce errors far away, often at the end of the file.
- Type syntax in JavaScript files (
: string,interface) gives TS8010-style errors instead when the file is not checked as TypeScript. - Newer syntax with older tools. A construct such as
using,satisfies, oraccessorfails to parse with a compiler that predates it. Check the installed version withtsc --version. - JSX in a
.tsfile is a syntax error; rename the file to.tsx. - Editor help. Bracket matching, a formatter such as Prettier and the TypeScript language server catch most of these as you type.