I'm curently learning Typescript and I'm having an issue ...
Type assignation for a function
Here are 2 simple sample of code, which are compiling in a different way and I don't get the reason.
1 Sample
testP(): Promise<number> {
return new Promise<string>((resolve, reject) => {
resolve("string");
});
}
This code returning in error during compilation as I'm not returning a number, that's fine.
2 Sample
testP(): Promise<number> {
return new Promise<any>((resolve, reject) => {
resolve("string");
});
}
This code is compiling without any bug and I don't know why ...
WHat is my mistake ? Thank you in advance !
Edit:
Here is what I'm actually trying to do
export interface Animal {
name: string,
weight: number,
age: number
}
getDogs(): Promise<Dog[]> {
return this.http.get('/dogs')
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
But like that, even if my "response" is not an array of "dogs", it doesn't trigger any error;
What am I missing ?