TypeScript: Missing type-check for generic types (?)
I’ve run into a mysterious case with a return-type that is clearly wrong - in methods like this one:
interface Foo {
a: string
b: number
}
class Hello {
getFoo(): Promise<Foo> {
return Promise.resolve("a string")
}
}
The declared return-type in this example is Promise<Foo>, but the function returns Promise<string>, yet there is no notice/warning/error for this - it compiles without complaint.
In fact, it doesn’t matter what I put in that return type-hint - I can return whatever I want, not just Promises, but any unrelated type, anything goes.
Is this really working as intended? What gives?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 18 (9 by maintainers)
Please follow contributing guide and provide a minimal reproducible example. I cannot know what happened without knowing
http.posttype.Confirmed. This is a duplication of https://github.com/Microsoft/TypeScript/issues/10524 and https://github.com/Microsoft/TypeScript/issues/10785. Fixed in https://github.com/Microsoft/TypeScript/commit/9d4219acf17e6b1e20279a331db12e13e94d4b58