Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
robertknight opened this issue Jan 24, 2015 · 2 comments
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@robertknight
Copy link

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.

@danquirk
Copy link
Member

This would reduce some noise. I'm not sure the cost of doing it is worth what's gained. Are there other languages that do this sort of thing?

@danquirk danquirk added the Suggestion An idea for TypeScript label Jan 26, 2015
@mhegazy mhegazy added the In Discussion Not yet reached consensus label Dec 8, 2015
@RyanCavanaugh RyanCavanaugh added Too Complex An issue which adding support for may be too complex for the value it adds and removed In Discussion Not yet reached consensus labels Jan 5, 2016
@RyanCavanaugh
Copy link
Member

There's just not a clean way to implement this in the compiler today (relative the gain in error quality)

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

4 participants