Skip to content
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

Document decode as function instead of method, to silence ESLint. #430

Open
patroza opened this issue Mar 28, 2020 · 8 comments
Open

Document decode as function instead of method, to silence ESLint. #430

patroza opened this issue Mar 28, 2020 · 8 comments

Comments

@patroza
Copy link

patroza commented Mar 28, 2020

🚀 Feature request

Current Behavior

flow(
    SomeIOType.decode,
    ... etc
)

Accessing .decode of a type by passing it, causes lint warning:
warning Avoid referencing unbound methods which may cause unintentional scoping of this @typescript-eslint/unbound-method

However the function is specifically bound: this.decode = this.decode.bind(this);

Desired Behavior

Passing .decode should not cause a warning

Suggested Solution

Document decode on the type as function instead of method.

Who does this impact? Who is this for?

Typescript users with recommended lint rules.

Describe

Your environment

Software Version(s)
io-ts 2.1.2
fp-ts 2.5.3
TypeScript 3.8.3
@gcanti
Copy link
Owner

gcanti commented Mar 28, 2020

Document decode on the type as function instead of method

@patroza could you please expand on that? What exactly means?

@patroza
Copy link
Author

patroza commented Mar 28, 2020

@gcanti hi, sure. in lib/index.d.ts:

decode(i: I): Validation<A>;
->
decode: (i: I) => Validation<A>;
or
readonly decode: (i: I) => Validation<A>;

@gcanti
Copy link
Owner

gcanti commented Mar 30, 2020

Isn't it a breaking change?

@patroza
Copy link
Author

patroza commented Mar 30, 2020

I don't believe so. Methods are more restrictive in this sense, and Functions less so.
The other way around, would imo be a breaking change. Or anything i'm overlooking?

@gcanti
Copy link
Owner

gcanti commented Mar 30, 2020

Could you please send a PR (or show a snippet) so we can reason about the actual changes?

@patroza
Copy link
Author

patroza commented Mar 30, 2020

Sure thing; #432

@aqrln
Copy link

aqrln commented Mar 30, 2020

Isn't it a breaking change?

Technically, yes: before the change both Type.prototype.decode and new Type().decode would have existed, but after the change only the latter one would.

Practically, no probably (unless someone is doing weird things with prototypes).

@maxdeviant
Copy link

Running into this same issue.

Would be great if we could get it resolved 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants