io-ts icon indicating copy to clipboard operation
io-ts copied to clipboard

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

Open patroza opened this issue 4 years ago • 8 comments

🚀 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

patroza avatar Mar 28 '20 17:03 patroza

Document decode on the type as function instead of method

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

gcanti avatar Mar 28 '20 18:03 gcanti

@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>;

patroza avatar Mar 28 '20 18:03 patroza

Isn't it a breaking change?

gcanti avatar Mar 30 '20 09:03 gcanti

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?

patroza avatar Mar 30 '20 09:03 patroza

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

gcanti avatar Mar 30 '20 09:03 gcanti

Sure thing; https://github.com/gcanti/io-ts/pull/432

patroza avatar Mar 30 '20 09:03 patroza

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).

aqrln avatar Mar 30 '20 09:03 aqrln

Running into this same issue.

Would be great if we could get it resolved 🙂

maxdeviant avatar Oct 27 '21 00:10 maxdeviant