Skip to content

Commit

Permalink
Merge pull request #1455 from balena-io/simplify-typed-results
Browse files Browse the repository at this point in the history
Simplify the custom pinejs-client typings after the Concept type unification
  • Loading branch information
thgreasi authored Oct 28, 2024
2 parents 9f1d46a + d5f61b0 commit 806455c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions typings/pinejs-client-core.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { WebResourceFile } from 'balena-request';
import type {
AnyObject,
PropsAssignableWithType,
PropsOfType,
StringKeyof,
Dictionary,
Expand Down Expand Up @@ -37,7 +36,6 @@ export type OptionalNavigationResource<T extends object> =
export type ReverseNavigationResource<T extends object> = T[] | undefined;

export type AssociatedResource<T extends object> =
| ConceptTypeNavigationResource<T>
| NavigationResource<T>
| OptionalNavigationResource<T>
| ReverseNavigationResource<T>;
Expand All @@ -55,18 +53,14 @@ export type SelectableProps<T> =
>; // This is the normal typed case

export type ExpandableProps<T> = PropsOfType<T, AssociatedResource<object>> &
// TODO: Drop me once Pine unifies ConceptTypeNavigationResource with NavigationResource
PropsAssignableWithType<T, [] | [any] | any[]> &
string;

type SelectedProperty<T, K extends keyof T> =
T[K] extends NavigationResource<any>
? PineDeferred
: T[K] extends OptionalNavigationResource<any>
? PineDeferred | null
: T[K] extends ConceptTypeNavigationResource<any>
? Exclude<T[K], any[]>
: T[K];
: T[K];

type SelectResultObject<T, Props extends keyof T> = {
[P in Props]: SelectedProperty<T, P>;
Expand All @@ -92,7 +86,7 @@ type ExpandedProperty<
> =
KOpts extends ODataOptionsWithCount<any>
? number
: T[K] extends NavigationResource<any> | ConceptTypeNavigationResource<any>
: T[K] extends NavigationResource<any>
? [TypedResult<InferAssociatedResourceType<T[K]>, KOpts>]
: T[K] extends OptionalNavigationResource<any>
? [TypedResult<InferAssociatedResourceType<T[K]>, KOpts>] | []
Expand Down

0 comments on commit 806455c

Please sign in to comment.