Even though the rxjs imports are correctly set up, the 'map' property is not found on the 'Observable<Response>' type

I'm currently developing a MEAN stack application using Angular 2.

Despite finding similar inquiries on StackOverflow, I've explored various solutions without success. While many suggest importing the entire rx/js library along with map or using:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

However, none of these configurations seem to resolve the issue for me. The error persists when using .map in my service. I attempted updating both global typescript and the version specified in dependencies but encountered the same error post 'ng serve'. It appears to be a typescript-related problem, though it remains ambiguous since importing observables did not fix it.

Package.json

{
  "name": "aether-news",
  "version": "0.0.0",
  "license": "MIT",
  ... (omitted for brevity)
}

Imports in my service

import { Injectable } from '@angular/core';
... (imports omitted for brevity) 
import 'rxjs/add/operator/map';

Service Code

import { Injectable } from '@angular/core';
... (imports and code omitted for brevity) 

@Injectable()
export class NewsApiService {
  ... (properties and methods omitted for brevity)

//EVENT REGISTRY
//BBC
getEventRegistryBBC(){
  return this.http.get("http://eventregistry.org/json/article?sourceUri=bbc.co.uk&sourceUri=bbc.com&categoryUri=dmoz%2FSociety%2FPolitics&action=getArticles&articlesSortBy=date&resultType=articles&articlesCount=200&articlesIncludeArticleDuplicateList=true&articlesIncludeArticleCategories=true&articlesIncludeConceptImage=true&articlesIncludeConceptDescription=true&articlesIncludeConceptDetails=true&articlesIncludeConceptTrendingScore=true&articlesIncludeSourceDescription=true&articlesIncludeArticleImage=true&articlesIncludeSourceDetails=true")
    .map((res) => {
      this.eventRegistryBBC = res.json()
      return res.json().articles.results;
    })
}

Please share if you've encountered a similar issue despite correctly importing rxjs library. Thanks for your help.

Answer №1

When it comes to my services, I always make sure they are typed (check out Observable) and avoid using multiple returns - not entirely certain about how that would function.

Typically, my services involve returning data using this.http.get method and then mapping the response with response.json().

In the component, I subscribe to the Observable and carry out any necessary data manipulations to extract specific information.

Perhaps you could experiment with something similar to the example below?

getEventRegistryBBC(): Observable<Response>{
  return this.http.get("http://eventregistry.org/json/article?sourceUri=bbc.co.uk&sourceUri=bbc.com&categoryUri=dmoz%2FSociety%2FPolitics&action=getArticles&articlesSortBy=date&resultType=articles&articlesCount=200&articlesIncludeArticleDuplicateList=true&articlesIncludeArticleCategories=true&articlesIncludeConceptImage=true&articlesIncludeConceptDescription=true&articlesIncludeConceptDetails=true&articlesIncludeConceptTrendingScore=true&articlesIncludeSourceDescription=true&articlesIncludeArticleImage=true&articlesIncludeSourceDetails=true")
  .map(response => response.json())
}

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

Encountering an error with RouterLink: 'frequency' property is undefined

In my Angular 4 project, I am encountering an issue with the following HTML code in my view: <p> You are on dashboard (first level); <a [routerLink]="['/second-dashboard', {frequency: frequency, datefrom: datefromparam, dateto: ...

Discover properties of a TypeScript class with an existing object

I am currently working on a project where I need to extract all the properties of a class from an object that is created as an instance of this class. My goal is to create a versatile admin page that can be used for any entity that is associated with it. ...

The specified property 'XYZ' is not found in the type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

Whenever I try to access .props in RecipeList.js and Recipe.js, a syntax error occurs. Below is the code snippet for Recipe.js: import React, {Component} from 'react'; import "./Recipe.css"; class Recipe extends Component { // pr ...

Error: Unable to assign generic type due to type mismatch

I'm struggling to understand the type error generated by the following code. Can anyone point out what I might be doing incorrectly? Type '(state: State) => State' is not assignable to type 'Action'. Types of parameters &apos ...

Leverage the Nuxeo client SDK with Angular 6 for seamless integration with RESTClient in

Looking to integrate the Nuxeo ClientSdk with my Angular 6 client to consume its REST API, but facing issues due to the lack of typescript definitions for this JavaScript package. Tried importing the library into my project using the following code snippe ...

Some code paths fail to return a value in Google Cloud Function callable functions

When utilizing async functions in my cloud function and including a 'return' statement in each potential output, I am still encountering the error message Not all code paths return a value I attempted removing my database calls and only leaving ...

What is the correct way to access and assign a value from a different getter or setter? I am facing an issue with the creation of my second array

Two http GET API calls are being made in the constructor. The first call is working fine and has a getter/setter to filter the main array (studentNameData) into a filtered array (filteredName). However, the second call is also trying to do the same thing b ...

Prevent the "Ok" button from showing on the keyboard in an Ionic 2 form

I developed an innovative Ionic 2 application with a form feature. Within my forms, there is the option to input type "text", which naturally prompts the device's keyboard to appear. However, I encountered an issue where pressing the "Ok" button on th ...

Utilizing generics within a function

Can you help me understand why I am getting an error message that says "Type 'AbstractPopup' is not assignable to type T" when using the return statement in the popupFactory(...) method? This code is just a test example for learning how generics ...

I'm curious about why the value of my variable in service.ts keeps changing whenever the page is refreshed?

Below is my Angular service.ts file code. It is used to store the login status. import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Injectable({ providedIn: 'root' }) e ...

Angular2: Unable to find json property on object type

I am a beginner and struggling to solve this problem. I have tried to understand the errors but it's still not making sense to me. Whenever I use .map or .subscribe on the service, I get an error saying Property 'json' does not exist on typ ...

Tips for utilizing various environment files for the "development" and "production" phases in the "aws-nodejs-typescript" template

I have utilized the "aws-nodejs-typescript" template from "serverless" to create a serverless function. My goal is to employ separate .env files for the "dev" and "prod" stages. Is there a way to accomplish this? Upon deployment, the correct stage is not ...

How can I access members outside of a class without a name in Typescript?

I recently developed an "anonymous" class inspired by this insightful discussion on Typescript anonymous classes. However, I'm facing a challenge in accessing the outer scope members. Here's a snippet of my code for context: class BaseCounter { ...

Angular 6's inability to subscribe to a subject from multiple components simultaneously is causing issues

Having an issue with data subscription between parent and child components and a service. When emitting data using the next method in the subject class, only the child component receives the data. In navbar.component.ts: this.messageService.setClientUser ...

The error message "TypeError: Unable to access the 'getFullWidth' property of an undefined value when using TSLint and TypeScript" was

I have been using Dan Wahlin's tutorials and online examples to set up Gulp and Typescript, but I am facing an issue with the tslint() function. The problem occurs in my code as follows: node_modules\tslint\lib\language\walker&bso ...

"Ionic Calendar 2 - The ultimate tool for organizing your

I am using a calendar in my Ionic app that retrieves events from a database through an API. var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://portalemme2.com.br/SaoJoseAPI/agenda', true); this.http.get('http://portalemme2.c ...

Encountering errors during ng build after transitioning from Angular 2.4 to Angular 5.0

Following the successful upgrade of my Angular 2.4 app to Angular 5.0, which involved upgrading the CLI and Angular version, I encountered an error when trying to run ng build. Here is the error that appeared: https://i.sstatic.net/awcLD.png. Any suggestio ...

Encountering Failures with 'npm install' on Specific Repositories

I recently acquired a bundle of Angular/Bootstrap4 templates from a source link to experiment with. However, I am encountering difficulties with the npm install step. After downloading the source and extracting the angular2seed project, I attempted the npm ...

Eliminate using a confirmation popup

My attempts to delete an employee with a confirmation dialog are not successful. I have already implemented a splice method in my service code. The delete function was functioning correctly before adding the confirmation feature, but now that I have upgrad ...

Having trouble locating the 'tsc-watch' module due to the missing 'typescript/bin/tsc' when running the TypeScript compiler

Encountering the error "Cannot find module 'typescript/bin/tsc' when attempting to run tsc-watch yarn tsc-watch --noClear -p tsconfig.json yarn run v1.22.19 $ /Users/jason/Work/VDQ/VDQApp/node_modules/.bin/tsc-watch --noClear -p tsconfig.json Ca ...