8000 Parameter signatures of functions in object literals are not always inferred correctly. · Issue #4241 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Parameter signatures of functions in object literals are not always inferred correctly. #4241
Closed
@rjamesnw

Description

@rjamesnw

Hi, I ran into an issue where the types don't seem to be inferred correctly. Consider this:

interface ITestHandler { (a: string, ...args: any[]) }
interface ITestHandlers { [index: string]: ITestHandler; }
class Test { Events: ITestHandlers; }
var t = new Test();
t.Events = {
     handler1: (a) => { }, // <= this works fine, 'a' is 'string'
     handler2: (a, b: string) => { } // <= 'a' is 'any', but 'b' is optional in the interface!
};

I expect "a" for "handler2" to be "string", but instead it is "any". Shouldn't "a" be interred from the signature, since the "args" are of type "any", which should match any type?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0