-
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
A bit cryptic description, I know, but maybe the following example clarifies the issue:
import { array, Decoder, object } from "decoders"
type GenericArrayContainer<F> = {
value: F[]
}
// inferred type matches declared type
const genericArrayContainer = <F>(decoder: Decoder<F>): Decoder<GenericArrayContainer<F>> => object({
value: array(decoder),
})
type GenericValueContainer<F> = {
value: F
}
// inferred type does not match declared type
const genericValueContainer = <F>(decoder: Decoder<F>): Decoder<GenericValueContainer<F>> => object({
value: decoder,
})as commented, in the first case the type is inferred correctly when the generic value is wrapped in another decoder, but if the field is declared with the dynamically passed decoder directly, type inference no longer works.
This was tried with:
"decoders": "^2.0.1",
"typescript": "^4.9.4"
Let me know if there is another approach to achieving what I'm trying to do here or if any further info is required.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels