The 'flatMap' property is not found on the 'string[]' data type. This issue is not related to ES2019

A StackBlitz example that I have set up is failing to compile due to the usage of flatMap. The error message reads:

Property 'flatMap' does not exist on type 'string[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later.

I attempted changing the lib to 'es2019' after consulting this post about flatMap, flat, flatten doesn't exist on type any[], but unfortunately, it did not resolve the issue.

Exploring other solutions from related queries, I also experimented with 'esnext'. However, this approach proved ineffective as well.

The excerpt from my tsconfig file looks like this:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    ...
    "lib": ["es2019"]
  },
  ...
}

This is a portion of the code where flatMap is invoked:


import { Component, VERSION } from '@angular/core';
import { get } from 'lodash';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  ...
  ngOnInit() {
    const testData = [...];
    testData['columns'] = ['name', 'count', 'successes'];
    const countCategoryArr: Array<string> = get(testData, 'columns', []).slice(1);
    const moveCounts = countCategoryArr.flatMap((entry) =>
      hist.map((d) => ({
        move: d.name,
        countCategory: entry,
        count: d[entry],
      }))
    );
  }
}

The error displayed on StackBlitz can be viewed https://i.sstatic.net/bcMFj.jpg

Answer №1

The reason for the issue is not clear, but turning off Ivy resolves it:

"angularCompilerOptions": {
    "enableIvy": false,
    ...
  }

https://example.com/edit/angular-ivy-hvpfty?file=tsconfig.json

I couldn't replicate it on my machine, so it appears to be a bug in the ivy compiler specifically on stackblitz.

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

Angular displays X items in each row and column

I've been struggling with this task for the past 2 hours. My goal is to display a set of buttons on the screen, but I'm facing some challenges. The current layout of the buttons doesn't look quite right as they appear cluttered and unevenly ...

Having difficulty adjusting the configuration settings for an embedded report within Angular 7

While attempting to integrate a Power BI report with Angular 7, I encountered an unexpected error when trying to configure the settings of the report. The error message stated: Type '{ filterPaneEnabled: boolean; navContentPaneEnabled: boolean; }&apos ...

Bringing in information from a TypeScript document

I'm having trouble importing an object from one TypeScript file to another. Here is the code I am working with: import mongoose from "mongoose"; import Note from './models/notes'; import User from './models/users'; import ...

What is a way to execute a series of requests using rxjs similar to forkJoin and combineLatest, without needing to wait for all requests to finish before viewing the results?

Consider you have a list of web addresses: urls: string[] You create a set of requests (in this instance, utilizing Angular's HTTPClient.get which gives back an Observable) const requests = urls.map((url, index) => this.http.get<Film>(url) ...

Trouble encountered with uploading files using Multer

I am facing an issue with uploading images on a website that is built using React. The problem seems to be related to the backend Node.js code. Code: const multer = require("multer"); // Check if the directory exists, if not, create it const di ...

Issues arise when attempting to store data in an array in Angular using Typescript

Having an issue where my benchmark foreach loop is not correctly storing all values in the array. Instead, it only saves one value and returns a null error. Strangely, if I remove the push function and replace it with a console.log, all results are displ ...

Experiencing a type error within Redux in a React Native project utilizing TypeScript

I am currently working on implementing a feature to store the boolean value of whether a phone number is verified or not. Within my login component: await dispatch(setOTPVerified(data.is_phone_verified)); Action.tsx: export const OTP_VERIFIED = 'OTP ...

Does anyone know of a custom typeguard that enforces the presence of elements in an array?

I need help creating a custom type guard to determine if an array contains nullable or optional elements. I have defined a helper type called RequiredArray: type RequiredArray<A extends readonly any[]> = A extends [infer P, ...infer R] ? [Non ...

The error message "SyntaxError: Cannot use import statement outside a module" popped up while working with discord.js, typescript, heroku

// Necessary imports for running the discord bot smoothly import DiscordJS, { TextChannel, Intents, Message, Channel, NewsChannel, ThreadChannel, DiscordAPIError } from 'discord.js' type guildTextBasedChannel = TextChannel | NewsChannel | ThreadC ...

Struggling to integrate Docker compatibility into an established NextJS project, encountering the frustrating "stat app/.next/standalone: file does not exist" message

I'm currently in the process of enhancing my existing NextJS + TypeScript project with Docker support and preparing to deploy it on Google Cloud Run. To achieve this, I've been referring to a helpful guide available at: https://github.com/vercel/ ...

I'm curious if there is an eslint rule specifically designed to identify and flag any unnecessary spaces between a block comment and the function or

Can anyone help me find a solution to prevent the following issue: /** * This is a comment */ function foo() { ... } I need it to be corrected and formatted like this: /** * This is a comment */ function foo() { ... } ...

Exploring Angular 9: Experimenting with iterating over a collection of objects and performing validations

Forgive me if this is a basic question, but I am new to Angular 9 and json. I am attempting to iterate through a list and only create a table row if the correct ID matches the ID passed from the previous page link. I am struggling to make the if statement ...

Utilizing Pipes within a Method in Angular 2 along with Dependency Injection triggers an "Insufficient Number of Arguments" error

I am searching for a solution to incorporate a custom pipe into my class. The custom pipe itself ( referenced from this source, many thanks ) involves injecting a dependency (the DomSanitizationService). import { Pipe, Inject, Injectable } from '@ang ...

Updating content in Angular 2 using PUT method with the "uri/list" content type for multiple elements

What is the process for sending multiple elements in a PUT request using Angular 2 and Typescript? In order to send multiple URIs, they must be separated by a line break: curl -i -X PUT -H "Content-Type:text/uri-list" --data-binary @uris.txt http://loc ...

The fusion of Typescript with Node.js

Currently, I am delving into learning typescript and exploring how to integrate it with Node.js. After watching multiple educational videos, I came across two distinct methods for linking typescript with Node.js. The first method involves using decorators, ...

Incorporating traditional Javascript classes for modeling in React development

Can traditional JavaScript classes be utilized in models within the MVC framework while using React, as opposed to relying on Redux or contexts & reducers which may impact reusability? If this approach is feasible, how can we efficiently 'subscribe&ap ...

Ways to override a method in Angular (Version 8 and above)

I am currently working with Angular 8. My goal is to customize the method function for the following code snippet: /** * This property allows you to override the method that is used to open the login url, * allowing a way for implementations to specify ...

The default value retrieved from an HTTP API and stored in a BehaviorSubject within a service

In my service, I am having an issue with getting the default value using a get HTTP request on a BehaviorSubject. Here is part of my code: defaultItems!: ColumnsToFilterWithItems[]; columnsToFilterWithItemsBehaviorSubject: BehaviorSubject<ColumnsToFilte ...

The TypeScript function was anticipating one argument, however it received two instead

Can you help me fix the issue with my createUser() function? Why am I unable to pass parameters in Smoke.ts? Login.ts : interface User { url: string, email: string, } class Test{ async createUser(user: User) { await Page.setUrl(user.url); aw ...

What purpose does a private property serve within the interface?

Given the following code snippet: class X { bar() { return "bar" } constructor(private readonly x: number){} } interface Y extends X { } const f = (y: Y) => { console.log(y.bar()); } f({ bar: () => "tavern"}); The code does ...