The name 'const' is missing or not found

While working on my Angular application, I attempted to utilize the Typescript 3.4 feature known as "const assertion" in the following manner:

const counterSettingsDefaults = { setTo: 10, tickSpeed: 200, increment: 1 } as const;

Unfortunately, this resulted in a compile error stating:

"Cannot find name 'const'.ts(2304)",

This error suggests that the functionality I'm trying to use may not be available.

After checking the versions of Angular and Typescript using ng --version in powershell, I found the following information:

 Angular: 9.0.0-rc.7 
 typescript: 3.6.4

If this is not supported, what could be causing the problem and where should I investigate further?

Answer №1

After much searching, I finally cracked the code to this issue. Victory!

To resolve this problem, follow these steps:

1. Open a TypeScript file.

2. Locate the TypeScript version in the Status Bar at the bottom right corner.

3. Select "Use Workspace Version" from the prompt that appears.

  • Find more details here

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

The const parameter needs to be more strictly const

Here's the snippet of code that is causing problems: #include <array> void foo(const int length) { std::array<int, length> arr; //line 4 } int main(){ const int length = 10; std::array<int,length> arr; } This code s ...

Is there a way for me to access the names of the controls in my form directly from the .html file?

I have a list where I am storing the names of my form controls. In order to validate these form controls, I need to combine their names with my code in the HTML file. How can I achieve this? Below is my code: .ts file this.form = this.formBuilder.group({ ...

Angular Test Error: Refactoring requires a source file to be present

Trying to execute the command ng test, I encountered an error message. How can this issue be resolved? I am unsure of its meaning. ERROR in Must have a source file to refactor. To eliminate this warning, use "ng config -g cli.warnings.versionMismatc ...

How can I specify the type of an object in Typescript to mirror a class's properties as a list?

This demonstration is kept simplistic and straightforward, yet the ultimate objective is far more intricate. It is crucial to grasp the method behind achieving this. Let's assume there exists a class class Foo { bar: string; baz: number; bob: a ...

Data from HTML not being transferred by Angular Forms

I am facing an issue with transferring input data from HTML's <select> element to Angular Forms. Let's take a look at my code first. File Name: home-page.component.html <form [formGroup]="rForm" (ngSubmit)="addPaste(rForm.value)"> ...

Refresh the page using a promise in Angular after a delay of 3 seconds

Currently, I am working on enhancing the functionality of the login page. In case a user enters an incorrect login and password combination, my goal is to have the page automatically reload after 3 seconds. Despite my best efforts, I have encountered chall ...

Advantages of passing individual variables instead of the entire object from HTML to JavaScript in AngularJS

When it comes to passing the iterating object from HTML to Javascript, there are two approaches that can be taken. The first approach involves passing the iterating object as a whole, while the second approach only passes the required properties of the obj ...

The type 'Argument of (props: ITableProps) => JSX.Element' cannot be assigned to the parameter type of... - React High Order Component

One of the tools I have in my arsenal is a loader HOC This is how the HOC looks like: const withLoader = <P extends object>(WrappedComponent: new () => React.Component<P, any>, loading: boolean) => { return class WithLoading extends ...

The bar chart functions perfectly on localhost but encounters issues after being hosted on Gitpage

Localhost Gitpage The bar chart was displaying correctly on localhost, but once it was hosted on Gitpage, it began to show issues. Any suggestions on how to resolve this? Repository Link: https://github.com/mzs21/bar-chart Live Preview: ...

tsc and ts-node are disregarding the noImplicitAny setting

In my NodeJS project, I have @types/node, ts-node, and typescript installed as dev dependencies. In the tsconfig.json file, "noImplicitAny": true is set. There are three scripts in the package.json file: "start": "npm run build &am ...

Angular Reactive Forms provide a method to connect a data object with each element within a FormArray

Currently, I am in the process of constructing a reactive form that resembles the image depicted below - In the image, each file (referred to as an attachment in the code) contains multiple agendas. These agendas can be added, updated, and deleted. https ...

How can I make the snackbar open multiple times in a row?

Check out this codesandbox I created to show an issue. When you click the button, a MUI snackbar opens. However, if you close it and try to reopen it, nothing happens. Do you think the problem is related to how I'm using hooks? Explore the sandbox h ...

What is the best way to filter by enum value in Typescript?

If I define an enum as follows: export enum Status { InProgress = 0, Completed = 1, Cancelled = 2 } and have a class that references the enum: import { Status } from "./Status"; export class TaskDto { public name: string = null; public c ...

Exploring subclasses in TypeScript

When working with TypeScript and defining an interface like the one below: export interface IMyInterface { category: "Primary" | "Secondary" | "Tertiary", } Can we access the specific "sub types" of the category, such as ...

Searching through an array of objects with ng2-completer does not yield any search results

Having some trouble with the ng2-completer plugin when trying to enable auto-complete functionality in a search box. The issue arises when attempting to use an array of objects instead of just strings, resulting in a 'No Results found' message. E ...

Prisma causing a compiler error

Currently, I am in the process of developing a project that integrates a GraphQL server and utilizes Prisma to establish a connection with the database. Additionally, I have chosen to implement this project using TypeScript. Unfortunately, as I compile my ...

Tips on implementing lazy loading for HammerJS in an Angular 9 application

In my Angular project, I utilize HammerJS to incorporate gestures such as panleft and panrigth in a lazy-loaded component. Despite having the lazy load component in a separate bundle during app building, hammer.js remains in node_modules within the main bu ...

Tips for concealing a parent within a complexly nested react router structure

Is there a more efficient way to conceal or prevent the rendering of parent content within a react router object? I could use conditional rendering, but I'm unsure if that's the optimal solution. My setup involves a parent, child, and grandchild, ...

Angular2 - Integration and utilization of the datepicker component

Is there a way to retrieve the selected date from an input and wrap it in a <p> tag? I've been attempting to use the jQueryUI datepicker and have tried binding events like change and click, but haven't had any success. Can anyone offer som ...

Unable to locate a supporting object labeled '[object Object]' with the type 'object' while attempting to access a local JSON file

What could be causing the following error message to appear: ERROR Error: Unable to locate a suitable object '[object Object]' of type 'object'. NgFor is only able to bind to Iterables such as Arrays. and how can this issue be reso ...