Skip to content

Broken type helper (GetPgResourceRelations) #1755

Open
@wesselvdv

Description

Summary

Various type helpers appear to be broken (GetPgResourceRelations) for example always returns any even when supplying a fully typed PgResource with explicit relations. I would advice to use infer instead of property access to prevent type erasure.

Below works:

type GetRegistry<U> = U extends PgResource<any, any, any, any, infer R>
  ? R
  : never
type GetRelations<U> = U extends PgRegistry<any, any, infer R> ? R : never
type GetCodec<U> = U extends PgResource<any, infer C, any, any, any>
  ? C
  : never
type GetName<U> = U extends PgCodec<infer N, any, any, any, any, any, any>
  ? N
  : never
type GetPgResourceRelations<U> = U extends PgResource<
  any,
  any,
  any,
  any,
  any
>
  ? GetRelations<GetRegistry<U>>[GetName<GetCodec<U>>]
  : never

Whereas this doesnt:

type GetPgResourceRelations<TResource extends PgResource<any, any, any, any, any>> = TResource["registry"]["pgRelations"][TResource["codec"]["name"]];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    🥚 Platypus

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions