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
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:
typeGetRegistry<U>=UextendsPgResource<any,any,any,any, infer R>
? R
: nevertypeGetRelations<U>=UextendsPgRegistry<any,any, infer R> ? R : nevertypeGetCodec<U>=UextendsPgResource<any, infer C,any,any,any>
? C
: nevertypeGetName<U>=UextendsPgCodec<infer N,any,any,any,any,any,any>
? N
: nevertypeGetPgResourceRelations<U>=UextendsPgResource<any,any,any,any,any>
? GetRelations<GetRegistry<U>>[GetName<GetCodec<U>>]
: never
Seems it's not entirely the fault of these type helpers. Seems I made some mistakes trying to make it fit into the existing PgRegistry which has type parameters that are narrowing too much.
Alright, looks like the issue is narrowing too much in the type parameters of PgRegistry. Causing typescript to get a union of "ExpliciitProperty" | string for relation properties which is the same as string.
I found when using inference that TypeScript would quickly resort to any's, potentially due to inference depth limits, but by using the [] syntax it would keep the types for a lot longer.
Summary
Various type helpers appear to be broken (
GetPgResourceRelations
) for example always returnsany
even when supplying a fully typedPgResource
with explicit relations. I would advice to useinfer
instead of property access to prevent type erasure.Below works:
Whereas this doesnt:
The text was updated successfully, but these errors were encountered: