Answer the question
In order to leave comments, you need to log in
Why doesn't typescript throw an exception for incorrect interface inheritance?
export interface Response {
success: boolean;
error: string;
data: {
token: string;
user: object;
};
}
this.http.post<Response>(`${environment.api}/some-route`, {})
.subscribe((response: Response) => {
console.log(response)
})
Answer the question
In order to leave comments, you need to log in
In every first textbook on TS, somewhere at the very beginning it is written that TS does not exist at runtime, so it cannot check anything there.
Have a look at io-ts and similar libraries for runtime validation
https://gcanti.github.io/io-ts/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question