io-ts
io-ts copied to clipboard
Document `decode` as function instead of method, to silence ESLint.
🚀 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 |
Document decode on the type as function instead of method
@patroza could you please expand on that? What exactly means?
@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>;
Isn't it a breaking change?
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?
Could you please send a PR (or show a snippet) so we can reason about the actual changes?
Sure thing; https://github.com/gcanti/io-ts/pull/432
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).
Running into this same issue.
Would be great if we could get it resolved 🙂