Skip to content

Missing type-check for generic types (?) #12023

Closed
@mindplay-dk

Description

@mindplay-dk

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions