0

I have this Http Call:

getSomething(): Observable<MyTypedClass> {
return this.httpClient.post<MyTypedClass>(this._url, httpOptions)
  .pipe(
    catchError(this.formatErrors)
  );

}

Where MyTypedClass.ts look like this:

export class MyTypedClass {
  code: string;
  state: string;
}

JSON Response (Missmatch MyTypedClass):

{ "code": "INF00001", "test":true }

Since my JSON response does not match MyTypedClass for test purposes.

Question: Should I expect the HttpClient throws some missmatch or parse error and fires the error function on subscribers?

1 Answer 1

2

TypeScript's type system in for compile-time only. It guides how you write your code, and is erased at runtime. You won't get any errors at runtime for JSON data not matching your class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.