Ts1005 expected ошибка

I am trying to learn Typescript and I’m following the tutorial on this page: https://www.typescriptlang.org/docs/handbook/functions.html. When I create a file cardPicker.ts and paste the following code, it won’t compile. I get this error 5 times: Typescript error TS1005: ‘;’ expected. Lines 1,6,7,14 and 15. I don’t see where a semicolon is missing, but maybe the error message means something else. I’m concerned about my version of ts, but I just installed that two weeks ago. When I do «tsc -version» it says 1.0.3.0

let deck = {
  suits: ["hearts", "spades", "clubs", "diamonds"],
  cards: Array(52),
  createCardPicker: function() {
     return function() {
         let pickedCard = Math.floor(Math.random() * 52);
         let pickedSuit = Math.floor(pickedCard / 13);

         return {suit: this.suits[pickedSuit], card: pickedCard % 13};
     }
  }
}

let cardPicker = deck.createCardPicker();
let pickedCard = cardPicker();

alert("card: " + pickedCard.card + " of " + pickedCard.suit);

I compile the project by running «tsc cardPicker.ts» in the command line.

Edited to add years later: Wanted to make it clear, I did not realize I had two versions of typescript on my computer- one was installed with Visual Studio a while back, and it was using that. Once I switched to use the node.js command prompt like bug-a-lot suggested in their answer below, it used the correct version. Using a regular windows command prompt, I could get it to work by navigating to the folder where tsc is found. It then successfully compiled without any changes to the code.

asked Jan 26, 2017 at 14:35

Kelly's user avatar

KellyKelly

9452 gold badges18 silver badges31 bronze badges

8

when you install tsc maybe you used npm install tsc -g

Following this link:
https://www.npmjs.com/package/tsc
this package where discontinued.

Now you should use npm install typescript -g then you will have the newer version.

Today tsc -v return Version 2.8.1

With newer version you do not will get ts1005

answered Apr 16, 2018 at 16:51

Airon Teixeira's user avatar

Is that everything you have in your ts file? Or do you have some reference comments in there too?

That error doesn’t complain about missing semicolon, as TypeScript doesn’t require you to use them at all, just like JS in that regard.

The error you’re getting instead is because something else didn’t make sense to the compiler, like a declaration that didn’t end properly. ( see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/4004 ). For example:

let deck: Number of Date;

Will produce that exact error.

Depending on your setup you might be compiling more than you might think.

In your case since your compiler is so old, it might just be that it doesn’t understand the keyword let which was introduced in TS 1.4.

UPDATE

To clarify, the command you used to install typescript installed latest.
But in order to use it, you need to run node.js command prompt instead of the normal Windows command prompt, assuming you are on Windows.

answered Jan 26, 2017 at 15:43

bug-a-lot's user avatar

bug-a-lotbug-a-lot

2,4461 gold badge22 silver badges27 bronze badges

1

Heyy @Kelli I got the same error, but I solved it. If you use visual studio then please copy your code in Visual Studio Code and select language as a typescript. And you getting red where you misspell after you indent your code and correctly add opening and closing brackets, add semicolons.

answered Dec 20, 2017 at 7:20

I spent a few hours today chasing a similar issue (my error was about a comma character) in a LESS pre-processor.

 error TS1005: ',' expected

Ended up that I had some backtick characters inside comments in my LESS files and they were confusing the pre-processor (maybe it is written in TypeScript -Angular 5 project- where the backtick has a special treatment)

answered Jan 4, 2018 at 4:19

Florin D's user avatar

Florin DFlorin D

1,63018 silver badges17 bronze badges

1

I had this very bizarre same error with errors like this :

Took me a little longer than it should to realize the path was duplicated

src/app/services/ was nested inside src/app/services/MYPROJECT. This was due to a bad path in a code gen and I hadn’t noticed the extra files.

src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(972,19): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(974,10): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(975,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(976,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(977,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(978,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(986,4): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(987,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(988,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(989,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(990,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(991,25): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(992,15): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(993,21): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(994,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(996,6): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(997,14): error TS1005: ';' expected.

answered Jul 9, 2018 at 1:49

Simon_Weaver's user avatar

Simon_WeaverSimon_Weaver

140k84 gold badges648 silver badges690 bronze badges

1

I have faced this issue.This can be happened because of the mismatch between Angular version and TypeScript version.So simply follow below steps

  1. Step 01 — Installing TypeScript for Visual Studio 2015

    • TypeScript for Visual Studio 2015
    • before install, check whether it is installed already(check the path
      C:\Program Files(x86)\Microsoft SDKs\TypeScript) and if it is there, then delete
      it.
    • then installed it and it will be in C:\Program Files (x86)\Microsoft
      SDKs\TypeScript\3.2
    • then set the path for TypeScript using path variable(set it as
      C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2)
  2. Step 02 — Installing latest Angular version(Angular 7) using following commands

    • npm install -g @angular/cli
    • npm install -g @angular/core
  3. Step 03 — Checking TypeScript version using following command

    • ng version
    • this will show typescript version, something like 3.2.4 (installed in
      previous step)

    • Specially, I like to thank to Shahriar Morshed and TranslucentCloud because I referred their answers to fix my issue.

answered Apr 30, 2019 at 12:28

Vidu VDS's user avatar

JSON may be missing curly braces.

In example, adding the two commented lines fixes the error.

const myObject =
[
  {
    'id': '123',
    'person': [
      {   // MISSING BRACE
        'name': 'SushiGuy',
        'age': '99',
      }   // MISSING BRACE
    ]
  }
];

answered Oct 8, 2021 at 20:42

SushiGuy's user avatar

SushiGuySushiGuy

1,57317 silver badges20 bronze badges

I am trying to learn Typescript and I’m following the tutorial on this page: https://www.typescriptlang.org/docs/handbook/functions.html. When I create a file cardPicker.ts and paste the following code, it won’t compile. I get this error 5 times: Typescript error TS1005: ‘;’ expected. Lines 1,6,7,14 and 15. I don’t see where a semicolon is missing, but maybe the error message means something else. I’m concerned about my version of ts, but I just installed that two weeks ago. When I do «tsc -version» it says 1.0.3.0

let deck = {
  suits: ["hearts", "spades", "clubs", "diamonds"],
  cards: Array(52),
  createCardPicker: function() {
     return function() {
         let pickedCard = Math.floor(Math.random() * 52);
         let pickedSuit = Math.floor(pickedCard / 13);

         return {suit: this.suits[pickedSuit], card: pickedCard % 13};
     }
  }
}

let cardPicker = deck.createCardPicker();
let pickedCard = cardPicker();

alert("card: " + pickedCard.card + " of " + pickedCard.suit);

I compile the project by running «tsc cardPicker.ts» in the command line.

Edited to add years later: Wanted to make it clear, I did not realize I had two versions of typescript on my computer- one was installed with Visual Studio a while back, and it was using that. Once I switched to use the node.js command prompt like bug-a-lot suggested in their answer below, it used the correct version. Using a regular windows command prompt, I could get it to work by navigating to the folder where tsc is found. It then successfully compiled without any changes to the code.

asked Jan 26, 2017 at 14:35

Kelly's user avatar

KellyKelly

9452 gold badges18 silver badges31 bronze badges

8

when you install tsc maybe you used npm install tsc -g

Following this link:
https://www.npmjs.com/package/tsc
this package where discontinued.

Now you should use npm install typescript -g then you will have the newer version.

Today tsc -v return Version 2.8.1

With newer version you do not will get ts1005

answered Apr 16, 2018 at 16:51

Airon Teixeira's user avatar

Is that everything you have in your ts file? Or do you have some reference comments in there too?

That error doesn’t complain about missing semicolon, as TypeScript doesn’t require you to use them at all, just like JS in that regard.

The error you’re getting instead is because something else didn’t make sense to the compiler, like a declaration that didn’t end properly. ( see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/4004 ). For example:

let deck: Number of Date;

Will produce that exact error.

Depending on your setup you might be compiling more than you might think.

In your case since your compiler is so old, it might just be that it doesn’t understand the keyword let which was introduced in TS 1.4.

UPDATE

To clarify, the command you used to install typescript installed latest.
But in order to use it, you need to run node.js command prompt instead of the normal Windows command prompt, assuming you are on Windows.

answered Jan 26, 2017 at 15:43

bug-a-lot's user avatar

bug-a-lotbug-a-lot

2,4461 gold badge22 silver badges27 bronze badges

1

Heyy @Kelli I got the same error, but I solved it. If you use visual studio then please copy your code in Visual Studio Code and select language as a typescript. And you getting red where you misspell after you indent your code and correctly add opening and closing brackets, add semicolons.

answered Dec 20, 2017 at 7:20

I spent a few hours today chasing a similar issue (my error was about a comma character) in a LESS pre-processor.

 error TS1005: ',' expected

Ended up that I had some backtick characters inside comments in my LESS files and they were confusing the pre-processor (maybe it is written in TypeScript -Angular 5 project- where the backtick has a special treatment)

answered Jan 4, 2018 at 4:19

Florin D's user avatar

Florin DFlorin D

1,63018 silver badges17 bronze badges

1

I had this very bizarre same error with errors like this :

Took me a little longer than it should to realize the path was duplicated

src/app/services/ was nested inside src/app/services/MYPROJECT. This was due to a bad path in a code gen and I hadn’t noticed the extra files.

src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(972,19): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(974,10): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(975,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(976,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(977,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(978,17): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(986,4): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(987,24): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(988,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(989,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(990,13): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(991,25): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(992,15): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(993,21): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(994,20): error TS1005: ';' expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(996,6): error TS1128: Declaration or statement expected.
src/app/services/MYPROJECT.NG/src/app/services/api/rr.api.ts(997,14): error TS1005: ';' expected.

answered Jul 9, 2018 at 1:49

Simon_Weaver's user avatar

Simon_WeaverSimon_Weaver

140k84 gold badges648 silver badges690 bronze badges

1

I have faced this issue.This can be happened because of the mismatch between Angular version and TypeScript version.So simply follow below steps

  1. Step 01 — Installing TypeScript for Visual Studio 2015

    • TypeScript for Visual Studio 2015
    • before install, check whether it is installed already(check the path
      C:\Program Files(x86)\Microsoft SDKs\TypeScript) and if it is there, then delete
      it.
    • then installed it and it will be in C:\Program Files (x86)\Microsoft
      SDKs\TypeScript\3.2
    • then set the path for TypeScript using path variable(set it as
      C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2)
  2. Step 02 — Installing latest Angular version(Angular 7) using following commands

    • npm install -g @angular/cli
    • npm install -g @angular/core
  3. Step 03 — Checking TypeScript version using following command

    • ng version
    • this will show typescript version, something like 3.2.4 (installed in
      previous step)

    • Specially, I like to thank to Shahriar Morshed and TranslucentCloud because I referred their answers to fix my issue.

answered Apr 30, 2019 at 12:28

Vidu VDS's user avatar

JSON may be missing curly braces.

In example, adding the two commented lines fixes the error.

const myObject =
[
  {
    'id': '123',
    'person': [
      {   // MISSING BRACE
        'name': 'SushiGuy',
        'age': '99',
      }   // MISSING BRACE
    ]
  }
];

answered Oct 8, 2021 at 20:42

SushiGuy's user avatar

SushiGuySushiGuy

1,57317 silver badges20 bronze badges

> tsc.cmd

node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - error TS1005: ']' expected.

4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                 ~

node_modules/firebase-functions/lib/function-configuration.d.ts:4:66 - error TS1134: Variable declaration expected.

4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                   ~~~~~~~~~~

node_modules/firebase-functions/lib/function-configuration.d.ts:4:153 - error TS1005: ';' expected.

4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                                                                                                          ~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:61 - error TS1005: ']' expected.

16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                               ~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:63 - error TS1134: Variable declaration expected.

16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                                 ~~~~~~~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:93 - error TS1005: ';' expected.

16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                                                               ~


Found 6 errors.

I have nested Object.assign() in typescript:

(<any>Object).assign({}, state, {
    action.item_id: (<any>Object).assign({}, state[action.item_id], {
        label_value: action.value
    })
})

This yields those errors:

ERROR in ./src/reducers/ItemsReducer.ts
(2,19): error TS1005: ':' expected.

ERROR in ./src/reducers/ItemsReducer.ts
(2,26): error TS1005: ',' expected.

ERROR in ./src/reducers/ItemsReducer.ts
(2,28): error TS1136: Property assignment expected.

The weird thing is that the errors vanish if I fix the key e.g.:

(<any>Object).assign({}, state, {
    "fixed_key": (<any>Object).assign({}, state[action.item_id], {
        label_value: action.value
    })
})

This left me clueless, why isn’t it ok to call action.item_id at that place when he doesn’t complain few characters after?

The «TS1005: ‘;’ expected (II)» error in TypeScript occurs when a semicolon is missing in a statement. It is a common error that occurs when the TypeScript compiler is expecting a semicolon to separate two statements, but it is missing. There are several methods to fix this error, including adding the missing semicolon, using a block statement, or reordering the statements.

Method 1: Add the missing semicolon

To fix the TypeScript error TS1005: ';' expected, you can add the missing semicolon at the end of the line where the error occurs. Here are a few examples:

Example 1: Missing semicolon after a variable declaration

let x = 10
let y = 20
console.log(x + y)

should be changed to:

let x = 10;
let y = 20;
console.log(x + y);

Example 2: Missing semicolon after a function declaration

function addNumbers(a: number, b: number) {
  return a + b
}
console.log(addNumbers(5, 10))

should be changed to:

function addNumbers(a: number, b: number) {
  return a + b;
}
console.log(addNumbers(5, 10));

Example 3: Missing semicolon after an object literal

let person = {
  name: 'John',
  age: 30
}
console.log(person.name)

should be changed to:

let person = {
  name: 'John',
  age: 30
};
console.log(person.name);

Example 4: Missing semicolon after an import statement

import { Component } from '@angular/core'
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'my-app'
}

should be changed to:

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'my-app';
}

By adding the missing semicolon, you can fix the TypeScript error TS1005: ';' expected. Remember to always double-check your code for missing semicolons, especially when copying and pasting code from different sources.

Method 2: Use a block statement

To fix TypeScript error TS1005: ‘;’ expected (II) with «Use a block statement», you need to wrap your code in a block statement. Here’s an example:

if (condition) {
  console.log("True");
} else {
  console.log("False");
}

In the above code, we’ve wrapped our console.log statements in a block statement using curly braces {}. This ensures that the code inside the if and else statements are treated as a single block of code, which resolves the TypeScript error.

Here’s another example:

for (let i = 0; i < 10; i++) {
  console.log(i);
}

In this code, we’ve wrapped our console.log statement inside a block statement using curly braces {}. This ensures that the console.log statement is treated as a single block of code, which resolves the TypeScript error.

To summarize, when you encounter the TypeScript error TS1005: ‘;’ expected (II), you can fix it by wrapping your code in a block statement using curly braces {}. This ensures that the code inside the block statement is treated as a single block of code, which resolves the TypeScript error.

Method 3: Reorder the statements

To fix the TypeScript error TS1005: ‘;’ expected (II) using «Reorder the statements» method, you can follow these steps:

  1. Identify the line where the error occurred.
  2. Look for any missing semicolons or syntax errors on that line.
  3. Reorder the statements on that line so that the missing semicolon or syntax error is fixed.

Here’s an example:

const myFunction = () => {
  const myVariable = "Hello World"
  console.log(myVariable)
}

In this example, the error occurs on the second line because there is no semicolon at the end of the statement. To fix this error using «Reorder the statements» method, we can move the variable declaration to a separate line and add a semicolon at the end of the console.log statement:

const myFunction = () => {
  const myVariable = "Hello World";
  console.log(myVariable);
}

By reordering the statements and adding the missing semicolon, we have fixed the TypeScript error TS1005: ‘;’ expected (II).

Another example:

const myObject = {
  name: "John Doe"
  age: 30
}

In this example, the error occurs on the second line because there is no comma separating the name and age properties. To fix this error using «Reorder the statements» method, we can reorder the statements and add a comma between the name and age properties:

const myObject = {
  name: "John Doe",
  age: 30
}

By reordering the statements and adding the missing comma, we have fixed the TypeScript error TS1005: ‘;’ expected (II).

Понравилась статья? Поделить с друзьями:
  • Trassir код ошибки no activity from channels
  • Tps abnml adj ошибка
  • Trassir ошибка определения модели
  • Tpms система контроля давления ошибка
  • Tpms ошибка хонда