How To Type Inference in Effect Library with Schema Structs

hello my effectful friends! wondering what I am doing wrong here to get good type infering?

import { Effect, pipe, Schema } from 'effect';

const Pokemon = Schema.Struct({
    name: Schema.String,
    weight: Schema.Number
});
type Pokemon = Schema.Schema.Type<typeof Pokemon>; // todo why not type infering?

//// HERE
/**
 * What I get:
    Effect.Effect<{ readonly name: string; readonly weight: number; }, Error | ParseError, never>
 * What I want:
    Effect.Effect< Pokemon, Error | ParseError, never >
 */
const getPokemon = (id: number) => pipe(
    Effect.tryPromise({
        try: () => 
            fetch(`https://pokeapi.co/api/v2/pokemon/${id}`)
                .then((res) => res.json())
        ,
        catch: (err: unknown) => new Error(`error fetching pokemon: ${err instanceof Error ? err.message : err}`)
    }),
    Effect.flatMap(p => Schema.decodeUnknown(Pokemon)(p))
)


thank you for any help πŸ™‚
Was this page helpful?