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.
> 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 am trying compile this typescript file:
import http = module("http");
import express = module("express");
With these parameters:
C:/nodejs/tsc.cmd --sourcemap cheese.ts --module commonjs
C:/User/Node/ExpressProject/cheese.ts(5,21): error TS1005: ';' expected.
C:/User/Node/ExpressProject/cheese.ts(6,24): error TS1005: ';' expected.
What am I doing wrong? Even with this, I am getting the same errors errors:
module "http" {}
module "express" {}
import http = module("http");
import express = module("express");
Using Typescript version 0.9.1
- Remove From My Forums
-
Общие обсуждения
-
Помогите понять, где ошибка в настройках visual studio code, пытаюсь компилировать код на TypeScript
let x: number = 1; let y: number = 2; let sum: number; sum = x + y; console.log(sum);
получается следующее:
PS D:1_GrettingStarted> tsc simple_script.ts
D:1_GrettingStartedsimple_script.ts(1,5): error TS1005: ‘;’ expected.
D:1_GrettingStartedsimple_script.ts(2,5): error TS1005: ‘;’ expected.
D:1_GrettingStartedsimple_script.ts(3,5): error TS1005: ‘;’ expected.
PS D:1_GrettingStarted>но в коде нет ошибок, он компилируется без проблем на другом компе, где были установлены теже версии nodejs и visual studio code, уже сносил и переустанавливал заново nodejs и visual studio code, но это не помогает.
-
Изменен тип
6 марта 2017 г. 12:31
тема неактивна
-
Изменен тип
Задача: При попытке скомпилировать TypeScript код, в консили отображается ошибка
.basic.ts(14,5): error TS1005: ‘;’ expected.
.basic.ts(15,5): error TS1005: ‘;’ expected.
Инструменты: Typescript Version 1.0.3.0
Решение: На первый взгляд код выглядит без ошибок, но не будем делать поспешных решений.
// create new instance
let firstCustomer = new Customer("Alex"); // line 14
let newMessage: string = firstCustomer.announce(); // line 15
Code language: TypeScript (typescript)
Сперва нужно проверить версию TypeScript’a. Для этого запустим терминал и выполним следующую команду:
tsc --version
или
tsc -v
У меня версия оказалась 1.0.3.0, а поддержка ключевого слова let (строка, на которую указывает ошибка) появилась только в версии 1.5, так что в моем случае нужно только обновить Typescript.
Так что обновляем TypeScript к нужной версии и наслаждаемся результатом. Как обоновить TypeScript описано тут.
PS: История изменений TypeScrip’a
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:
- Identify the line where the error occurred.
- Look for any missing semicolons or syntax errors on that line.
- 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).
So the only answers that even vaguely approach answering this seem to be on here. I’m pretty new to SPFX but am trying to build some book examples of React-Redux and I always come up against the same problems. First I download the samples, or implement the tutorials and they seem to work and serve fine until you get to add anything using office-ui-fabric-react controls. In this case:
<PrimaryButton
onClick={this.saveClick.bind(this)}
style={ { 'marginRight': '8px' } } >
Save
</PrimaryButton>
So this appears to be the version that ships with SPFX and I get onClick underlined and the error:
Property 'onClick' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes'
This is before I run gulp serve or try a build.
To get rid of this error I ended up reverting the version of office-ui-fabric-react to 4.14.1 and this now stops the error appearing in problems in VS Code — also had to revert the Typescript version to 2.2 from 3.x because it doesn’t seem to play nice. But now when I try and run gulp serve I get about 50 errors that look like:
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(18,59): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(18,61): error TS1005: '>' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(18,63): error TS1109: Expression expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(18,65): error TS1109: Expression expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(23,62): error TS1109: Expression expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(23,63): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(29,48): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(30,19): error TS1005: ':' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(31,20): error TS1005: ':' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(32,25): error TS1005: ':' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(33,22): error TS1005: ':' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(34,23): error TS1005: ':' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(44,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(48,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(52,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(56,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(56,30): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(60,50): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(67,36): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(74,42): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(84,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(91,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(97,4): error TS1005: ',' expected.
[10:33:52] Error - typescript - node_modules@uifabricutilitieslibBaseComponent.d.ts(105,4): error TS1005: ',' expected.
I get a bunch of other build errors as well but these are consistently always there. Most answers seem to tell me to change my version of typescript (2.2.2) or office-ui-fabric-react (4.14.1) but I’ve tried multiple versions to no avail.
Does anyone know what’s happening and how I even start to debug the problem?
If you’re getting the «ts1005 error in node_modules/rxjs/internal/types.d.ts(81,44)» error message, it can be frustrating and confusing. Fortunately, this error can be fixed with a few simple steps. In this guide, we will walk you through the process of troubleshooting and fixing this error.
This error message is related to TypeScript, a programming language that extends JavaScript. The error occurs in the «types.d.ts» file of the «rxjs» library, which is a popular library used for reactive programming. The error message indicates that there is a syntax error in line 81, column 44 of the file.
Why am I getting this error?
There are several reasons why you might be getting this error message. The most common reasons are:
- A syntax error in your code
- A version conflict between the «rxjs» library and TypeScript
- A corrupted installation of the «rxjs» library
How to fix the ts1005 error in node_modules/rxjs/internal/types.d.ts(81,44)
To fix this error, follow these steps:
Check your code for syntax errors: The first step is to check your code for any syntax errors. Look for any missing or misplaced brackets, parentheses, or semicolons. Fix any syntax errors that you find.
Update your TypeScript version: If your TypeScript version is outdated, it may be causing a conflict with the «rxjs» library. Update your TypeScript version to the latest version.
Reinstall the «rxjs» library: If none of the above steps work, try reinstalling the «rxjs» library. You can do this using the following command:
npm uninstall rxjs
npm install rxjs
This will uninstall and then reinstall the «rxjs» library.
FAQs
Q1. What is TypeScript?
TypeScript is a programming language that extends JavaScript. It adds features such as static typing, classes, interfaces, and modules to JavaScript.
Q2. What is the «rxjs» library?
The «rxjs» library is a popular library used for reactive programming in JavaScript and TypeScript. It provides a set of utilities for working with asynchronous data streams.
Q3. How do I check my TypeScript version?
You can check your TypeScript version by running the following command in your terminal:
tsc -v
This will display your TypeScript version.
Q4. What is a syntax error?
A syntax error is a type of error that occurs when there is a mistake in the way your code is written. It can be caused by missing or misplaced brackets, parentheses, semicolons, or other syntax elements.
Q5. What is reactive programming?
Reactive programming is a programming paradigm that focuses on asynchronous data streams and the propagation of changes. It is often used in web development and user interface programming.
- TypeScript official website
- RxJS official website
- Stack Overflow thread on fixing ts1005 error