Skip to content

Error messages are difficult to parse when class incorrectly implements an interface #1796

Closed
@robertknight

Description

@robertknight

If a class incorrectly implements an interface which it explicitly claims to implement, the compiler produces "Argument of type '' is not assignable to parameter of type ''" at all the locations where an instance of the class is assigned to a variable or function parameter of the interface type.

This results in a lot of redundant error messages which obscure the root issue - the error message explaining why the class doesn't implement the interface.

I would suggest that if a class explicitly claims to implement an interface, that call-sites shouldn't issue errors about type incompatibilities.

eg. With this code:

interface WebServiceClient {
    getData(): string;
}

class WebServiceImpl implements WebServiceClient {
    getData(): number { // incorrect implementation
        return 0;
    }
}

function doSomethingWithWebService(client: WebServiceClient): void {
}

var webService = new WebServiceImpl();
doSomethingWithWebService(webService);

Don't produce the "Argument of type 'WebServiceImpl' is not assignable to parameter of type 'WebServiceClient'" error at the doSomethingWithWebService() call, only the error for the WebServiceImpl implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions