Skip to content

Overload on constants: type checking additional parameters #191

Closed
@NoelAbrahams

Description

@NoelAbrahams

Hi, consider this bit of code:

class Bar {
    public bar: string;
}
interface IFoo {
    doFoo(type: any, bar: any): void;
    doFoo(type: "Quux", bar: Bar): string;
}

We use it like this:

var foo: IFoo;
var result:string = foo.doFoo("Quux", new Bar()); // fine

However, while still specifying "Quux", if we pass any type other than new Bar() for the second argument, the compiler falls back to the non-overloaded method:

// Error TS2011: Cannot convert 'void' to 'string'.
var result2: string = foo.doFoo("Quux", "bar");

I think this is a bit unfortunate. We are missing an opportunity to verify that the additional arguments also match the overloaded signature.

Ideally the following

foo.doFoo("Quux", "bar");

should generate error TS2082: Supplied parameters do not match any signature of call target

See further discussion on the old codeplex site.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions