Closed ingun37 closed 3 years ago
Is there a workaround for this?
Is there a workaround for this?
io-ts-types
is using the old Decoder interface (exported from io-ts/index.ts
). If you want to use the new, experimental Decoder interface (exported from io-ts/Decoder.ts
, you need to implement most of (all of?) io-ts-types
yourself, or switch back to using the old interface.
you could define an adapter, here's a (simplistic) solution
import * as t from 'io-ts'
import * as D from 'io-ts/Decoder'
import { pipe } from 'fp-ts/function'
import * as E from 'fp-ts/Either'
export function toDecoder<A, O, I>(type: t.Type<A, O, I>): D.Decoder<I, A> {
const decode = type.decode.bind(type)
return {
decode: (i) =>
pipe(
decode(i),
E.mapLeft(() => D.error(i, type.name))
)
}
}
import { withFallback } from 'io-ts-types/withFallback'
export const MaterialInfo = D.type({
mapElement: D.type({
uiID: toDecoder(withFallback(t.number, -1))
})
})
🐛 Bug report
Current Behavior
When I do
I get Error
Expected behavior
I expect Decoder from
io-ts/lib/index
and Decoder fromio-ts/lib/Decoder
to not conflict each other.Reproducible example
Suggested solution(s)
Additional context
Your environment
Which versions of io-ts-types are affected by this issue? Did this work in previous versions of io-ts-types?