You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import * as S from 'io-ts/Schema'
const PersonSchema = MySchema.make((S) =>
S.struct({
name: S.string,
age: S.Int
})
)
type Person = S.TypeOf<typeof PersonSchema>
// ^ it is never
because Schemable in Schema is contravariant
Desired Behavior
type Person = S.TypeOf<typeof PersonSchema>
/*
type Person = {
name: string;
age: Int;
}
*/
Suggested Solution
in document, add a step: export type TypeOf<S> = S extends MySchema<infer A> ? A : never
and when need extracting static types, use MySchema.TypeOf instead of Schema.TypeOf
maybe Schema.TypeOf can be type TypeOf<S> = S extends (i: any) => HKT<any, infer R> ? R : never. I don't known
Who does this impact? Who is this for?
All users
Describe alternatives you've considered
Additional context
Your environment
Software
Version(s)
io-ts
2.2.16
fp-ts
2.11.8
TypeScript
4.7.0-dev.20220419
The text was updated successfully, but these errors were encountered:
馃殌 Feature request
Current Behavior
When I extended my Schema according to How to extend the built-in Schema, I couldn't use
Schema.Typeof
to get the typesbecause
Schemable
inSchema
is contravariantDesired Behavior
Suggested Solution
export type TypeOf<S> = S extends MySchema<infer A> ? A : never
and when need extracting static types, use
MySchema.TypeOf
instead ofSchema.TypeOf
Schema.TypeOf
can betype TypeOf<S> = S extends (i: any) => HKT<any, infer R> ? R : never
. I don't knownWho does this impact? Who is this for?
All users
Describe alternatives you've considered
Additional context
Your environment
The text was updated successfully, but these errors were encountered: