Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[explicit-function-return-type] request option for curried arrow functions #193

Closed
Labels
enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulehas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@skylize

Description

@skylize

Proposal

Additional option forexplicit-function-return-type ignores all but the final returned function when multiple fat-arrows appear in a function expression before a shared body.

{"rules": {"@typescript-eslint/explicit-function-return-type": ["error",      {"allowCurrying":true      }    ]  }}

Purpose

In functional programming, currying is a common pattern. With this pattern a function taking multiple parameters is instead modeled as a unary (1-parameter) function that returns a unary function that returns a unary function, .etc. With arrow functions, you can express this quite elegantly, but the intermediate return types are (usually) not of meaningful importance.

Example

Good: Explicit return given for last function returned by expression.

constfoo=(bar:string)=>(baz:string)=>(buz:string)=>(biz:string) :string=>`${bar}${baz}${buz}${biz}`constfiz=foo('bar')('baz')('buz')('biz')

Bad: Applied all parameters, but still failed to express a return type.

constbadFoo=(bar:string)=>(baz:string)=>(buz:string)=>(biz:string)=>`${bar}${baz}${buz}${biz}`

Note that in the example, there are technically 4 different functions in thefoo expression. But from a conceptual level, you can think of it as 1 function that must be called 4 times to apply all the parameters.

The type offoo( 'bar' ) is "foo with the first parameter fixed as'bar'". Trying to express that explicitly through the type system is a painful exercise in meaningless verbosity.

However, onceall the parameters are given, it still makes sense to enforce an explicit return type for the final returned value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulehas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp