#i'm using this linter. I'm receiving an object using HttpClient.get.

12 messages · Page 1 of 1 (latest)

red elbow
#

The linter sugest to use const as a variable, as the variable is not reassigned. But the .get method returns an observable of an object. Does that make sense or should i use let instead? I'm feeling confused as i want to do it the best possible and following best practices.

glossy lion
#

I don't know why you're assigning the emission of an observable from an XHR to a variable, considering that usually those ones get directly consumed through aync pipe or alike.
In any case, the HttpClient requests emit and complete, so their emission cannot be reassigned.
But I find unlikely a linter to be aware of that.
Better if you post the interesting code, and a link to the linter you're using.

red elbow
#

alright man

#

a minute

#

findGenresByString(searchString: string): Observable<Genre[]> {
const url = environment.apiUrl+"/genero/generosPorString/"+searchString;
const result = this.httpClient.get<Genre[]>(url);
return result;
}

#

i'm returning the observable

#

and in the consuming class it has the different stages on a pipe

#

i'm using eslint

#

i tried using ng lint and didn't have one, vstudio sugested that one

#

it's really useful, i'm now seeing errors that vs haven't

#

and that suggested me to use const on those ones

glossy lion
#

You're not saving inside the var the mission of that observable.
You're saving the observable itself.
So, yes: even if that observable would emit multiple times (it will not)
your var would never be overwritten.
(nor storing that emission, not even the only one that will actually be produced)