Closed vecerek closed 2 years ago
@vecerek thanks for the bug report, I'm investigating. Looks like literal
doesn't work as expected inside a struct
with typescript@4.8
(while it works with typescript@4.7
and earlier versions)
Looks like changing the literal
signature from
export const literal: <A extends readonly [S.Literal, ...ReadonlyArray<S.Literal>]>(
...values: A
) => Decoder<unknown, A[number]>
to
export const literal: <A extends readonly [L, ...ReadonlyArray<L>], L extends S.Literal = S.Literal>(
...values: A
) => Decoder<unknown, A[number]>
solves the issue, PR here https://github.com/gcanti/io-ts/pull/657
🐛 Bug report
Current Behavior
Expected behavior
I expect the type to be inferred as:
Reproducible example
Suggested solution(s)
I tried changing
struct
in the Decoder to:to better align with the implementation of struct in
Codec
, where this inference issue does not happen.However, the type is then inferred as:
I suspect the implementation of
TypeOf
to be at fault there but I am not familiar with the theory behind Kleisli types, so it's become difficult for me to debug any further.Additional context
I stumbled upon this after upgrading to TypeScript 4.8 where it caused build errors. My workaround to this issue was to cast the string to a const:
Your environment
Which versions of io-ts are affected by this issue? Did this work in previous versions of io-ts?
This issue should be reproducible on the master branch. I don't know if the inference ever worked.