Closed silasdavis closed 1 year ago
After a sleep I realise I am being dumb here.
io-ts runtime types may be isomorphic to compile-time types but they do not themselves obey a covariant runtime hierarchy over the schemas.
exit stage left
Well in case anyone else finds themselves in a similar quagmire the 'solution' is to use the compile-time A, O, I
types directly in the dependent classes like:
export class Extractor<
Scope,
ScopeO extends Json,
Output,
OutputO extends Json,
>
Then reference them in the schema types like t.Type<Scope, ScopeO>
etc
I am struggling with a type:
The idea is to use this in a similar way to
AnyType
but with the requirement that it can beencode
d toJson
.I have a container type:
What I was hoping is that a variable of bare type
Extractor
is assignable from any more reifiedExtractor
but it does not seem to be the case.I'm struggling to come up with a minimal example, though I promise to try, but feel like I might need some pointers.
I have a function
function newExtractor(...) => new Extractor(...)
that compiles fine on its own (it's type is narrowed based on some specifict.Type
schemas that are passed in.However if I add
function newExtractor(...): Extractor => new Extractor(...)
I get a compile error like:It feels like this could be s contravariance thing?
Perhaps the issue with
_tag
is a stronger clue here.Anyway I appreciate this is a terrible report, I just want to not go off in the wrong direction if there is some direction I could get on how to craft a more minimal case.