gulp-typescript compiler encounters issues with the readonly keyword causing errors

Recently, I updated my application to use the latest versions of Angular 2 rc.6 and Angular Material 2 alpha 8-1. These updates require typescript 2, with the latter introducing the new readonly modifier.

To compile my .ts files, I rely on gulp-typescript, but since the package uses typescript 1.8.10, I am now encountering errors related to the readonly modifier. For example, this line:

readonly change: Observable<MdButtonToggleChange>;

Produces these compilation errors:

error TS1005: '=' expected.

error TS1005: ';' expected.

error TS1005: '(' expected.

It seems that the issue lies in the fact that gulp-typescript is not compatible with the new readonly modifier introduced in typescript 2.

Interestingly, none of my own code utilizes readonly; the errors are occurring solely in third-party typescript definition files (.d.ts) from the Angular 2 Material packages located within my node_modules/ folder. Despite attempting to exclude them in the tsconfig.json file like so:

"exclude": [
  "node_modules",
  "typings"
]

The errors persist.

  • Is there a solution to this problem?
  • If not, is there an alternative method to prevent the compiler from checking .d.ts files?

Answer №1

Yesterday, @cartant provided the correct answer which I just discovered a minute ago. Essentially, the solution involves configuring gulp-typescript to utilize typescript 2 instead of the default typescript 1.8. Here's how it's done:

1. Added typescript 2.0.2 as a devDependency in my package.json

"devDependencies": {    
  "gulp-typescript": "^2.13.6",
  "typescript": "^2.02"
}

2. Executed

npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6d2dfd6c3d5c5d4cfd6d2e69488968894">[email protected]</a>

3. Adjusted the configuration for creating my gulp-typescript project in gulpfile.js

Previous Configuration:

var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');

New Configuration:

var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json', {
    //Use TS version installed by NPM instead of gulp-typescript's built-in
    typescript: require('typescript')
});

More details. Now the compile-time errors have been resolved :-)

Answer №2

To enhance your project, you could incorporate TypeScript 2.0.2 RC as a dependency by running the command

npm install typescript@rc --save-dev
. Afterwards, pass it to gulp-typescript through the custom typescript option:

[...].pipe(ts({
    typescript: require('typescript')
}));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the steps to implement user authentication with a combination of username, password, and token in an Angular 4

After developing a form using Angular 4, I encountered the need to send the form data via the post method with Angular 4. Testing with Postman showed that the data is being received correctly. To accomplish this, I must use Basic Auth with a username and p ...

Discover the myriad of possibilities created by combining arrays

I am working on a code snippet that aims to generate an array containing all possible combinations between two or more arrays. However, I am encountering a specific issue. getCombn(arr: string | any[], pre?: string | undefined) { pre = pre || ' &a ...

Want to enhance user experience? Simply click on the chart in MUI X charts BarChart to retrieve data effortlessly!

I'm working with a data graph and looking for a way to retrieve the value of a specific column whenever I click on it, and then display that value on the console screen. Check out my Data Graph here I am using MUI X charts BarChart for this project. ...

Encountered a style group error 'non-collision' while using Angular with HERE Maps JS API 3.1

Occasionally, I encounter an error when trying to load a HERE map with the satellite base layer: Tangram [error]: Error for style group 'non-collision' for tile 13/16/15542/12554/15 Cannot read property 'retain' of undefined: TypeE ...

What steps can I take to troubleshoot the issue with ionicons not functioning properly?

After starting to work on my app with Ionic 2, the ionicons were displaying properly. But now, for some reason, they are not showing up at all. Do you have any idea why this might be happening? Is it necessary to add a specific library or something similar ...

Why does WebStorm fail to recognize bigint type when using TSC 3.4.x?

Currently, I am working on the models section of my application and considering switching from using number to bigint for id types. However, despite knowing that this is supported from TSC 3.2.x, WebStorm is indicating an error with Unresolved type bigint. ...

Issue: XHR failure (404 Not Found) while attempting to load angular2/http

I'm currently utilizing angular-cli for my Angular2 application. Whenever I attempt to load angular2/http in my Components/Services, no errors are displayed in the cli terminal. However, the browser's console shows the following message - GET ...

The Redux Toolkit slice and TypeScript were not in agreement: it was expecting 0 arguments, but received

Recently, I encountered an issue with my slice code: const investment = createSlice({ name: 'investments', initialState, reducers: { getInvestmentsRequest(state) { state.investments.status = RequestStatuses.loading; }, } }) ...

Variety of properties determined by a "type" prop, expanding variations based on a value from the interface

I am trying to enhance a type based on a value from the main interface. If the type == multiline, it will have a specific interface, and if the type == icon, it will have a different type. import React, { memo, useCallback, ReactNode } from 'react&apo ...

Leveraging IF conditions on part of the worksheet title

Currently, my script is performing the task of hiding three columns for tabs in a workbook that start with "TRI". However, the execution speed is quite sluggish. I am seeking suggestions on how to optimize and enhance the performance. If possible, please p ...

Cordova's FileReader takes precedence over TypeScript's FileReader functionality

I encountered an issue when adding the cordova-plugin-file-transfer plugin, where I received the error message: reader.addEventListener is not a function. This problem arises due to Cordova FileReader class overriding typescript FileReader. How can this ...

Is there a way to detect browser errors using JavaScript or Angular 2?

On the back-end, I am looking to add these uncaught errors to the log file. These errors are not being captured in angular2. How can I go about reading and handling these errors?https://i.sstatic.net/Kljon.png ...

Google Chrome does not display Set-Cookie header on page loads

Issue Having trouble with the Set-Cookie header not showing up in the response headers when making a request to a Spring Boot server's Post endpoint from an Angular app in Chrome's dev console. Summary of Findings Set-Cookie does appear in res ...

Instructions on how to present a list of employee information according to the user's gender preference using a selection of three radio buttons

I have developed a view that displays a table of employees, using a json array to store their details in the component. Additionally, I have implemented 3 radio buttons: all, male, and female. My goal is to have the table show all employees when "all" is ...

Display a targeted highcharts tooltip using React and typescript

In my React project with TypeScript, I am looking to have the Highchart tooltip appear when the chart is initially displayed. Specifically, I want it to show at a certain point on the chart. I understand that I will need to utilize a load function for thi ...

An application using NodeJS and ExpressJS is experiencing timeout issues when running with TAP testing

Currently, I am conducting tests on an ExpressJS (4.17.8) and NodeJS (16.3) powered server (app) using tap, followed by supertest. The initial focus is on testing the server instantiation, then moving on to its routes. To facilitate this process, my app i ...

Before utilizing in an Angular 6 template, it is essential to first parse the JSON content for the

I am currently working with Angular 6. Within the component file, I have an array object defined. items: Array<ItemData>; The interface ItemData has the following structure: export interface FavouriteProductData { id: number; type: string; ...

Is Angular CLI essential for building Angular applications?

Recently started working on a new project that uses Angular and I noticed in the package.json file these dependencies are listed: "@angular/common": "~8.0.0", "@angular/compiler": "~8.0.0", "@angular/core": "~8.0.0", "@angular/forms": "^8.0.3", "@angular/ ...

Developing a dynamic object deserializer in TypeScript/Angular 2

My background is in C# where I have experience working in a dynamic and reflective manner. Now, I am transitioning to TypeScript for writing a class and trying to apply similar principles. To provide context, I am converting an existing application into a ...

Type Error TS2322: Cannot assign type 'Object[]' to type '[Object]'

I'm facing an issue with a code snippet that looks like this: export class TagCloud { tags: [Tag]; locations: [Location]; constructor() { this.tags = new Array<Tag>(); this.locations = new Array<Location>(); ...