Skip to content

Error message for invalid string literal type could be improved #10203

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

Open
NoelAbrahams opened this issue Aug 8, 2016 · 1 comment
Open
Labels
Domain: Error Messages The issue relates to error messaging Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@NoelAbrahams
Copy link

TypeScript Version: 2.0 Beta

Code

// A *self-contained* demonstration of the problem follows...
interface Foo {

    method(value: 'aa'): void;
    method(value: 'bb'): void;
    method(value: 'zz'): void;
    method(value: 'last'): void;
}

const x: Foo = {} as any;

x.method('bar'); // Error line

Expected behavior:

A more meaningful error message, e.g.

Argument of type "'bar'" is not assignable to parameter of type "'aa' | 'bb'|...|'last'"

Actual behavior:

Argument of type "'bar'" is not assignable to parameter of type "'last'"

I am finding this error message confusing, because the compiler picks the value of the last overload in order to report the error, and there is nothing special about the last value.

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". labels Aug 8, 2016
@DanielRosenwasser DanielRosenwasser added this to the Community milestone Aug 8, 2016
@DanielRosenwasser DanielRosenwasser added the Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. label Aug 8, 2016
@DanielRosenwasser
Copy link
Member

I've rated this at moderate difficulty because overload resolution isn't the simplest part of the compiler.

For what it's worth, I don't think the suggested error message is the best because it implies you could actually pass in a value of type "aa" | "bb" | ... | "last", but that's not the case.

Also see @sandersn's issue at #6541.

@DanielRosenwasser DanielRosenwasser added the Domain: Error Messages The issue relates to error messaging label Aug 8, 2016
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants