Skip to content

Proposal for Parameter Type Inference for immediately invoked anonymous functions #4142

Closed
@aersam

Description

@aersam

I have to target ES3/ES5 and I quite often find myself writing something like this:

for (let roleType of this.RoleTypes) {
    ((roleType) => {
        //roleType is of type any, but should be typeof "outer" roleType
            observable.subscribe((nv) => {//Do something with it in a function
                this.afunction(nv, roleType2.RoleTypeID);
            });                                    
    })(roleType); //Protect variable scope
}

or something like this:

(($) => {
    //Why not infer $ as typeof jQuery?
})(jQuery);

I think it was reasonable to infer the parameter type from its only usage here

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA 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