Skip to content

Commit

Permalink
docs: Ambient type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 26, 2024
1 parent 3fa9eb9 commit b6298e7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface EntityPath {
key: string;
pk: string;
Expand Down Expand Up @@ -105,14 +114,6 @@ type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S e
} ? NormalizeReturnType<S['_normalizeNullable']> : S extends Serializable<infer T> ? T : S extends Array<infer F> ? Normalize<F>[] | undefined : S extends {
[K: string]: any;
} ? NormalizedNullableObject<S> : S;
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

/** Maps a (ordered) list of dependencies to a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

type AbstractInstanceType<T> = T extends new (...args: any) => infer U ? U : T extends {
prototype: infer U;
} ? U : never;
Expand Down Expand Up @@ -70,14 +79,6 @@ type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S e
interface EntityMap<T = any> {
readonly [k: string]: EntityInterface<T>;
}
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface SnapshotInterface {
readonly fetchedAt: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

type AbstractInstanceType<T> = T extends new (...args: any) => infer U ? U : T extends {
prototype: infer U;
} ? U : never;
Expand Down Expand Up @@ -70,14 +79,6 @@ type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S e
interface EntityMap<T = any> {
readonly [k: string]: EntityInterface<T>;
}
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface SnapshotInterface {
readonly fetchedAt: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface EntityPath {
key: string;
pk: string;
Expand Down Expand Up @@ -139,14 +148,6 @@ interface NormalizeMeta {
date: number;
fetchedAt: number;
}
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

declare function denormalize<S extends Schema>(schema: S | undefined, input: any, entities: any, args?: readonly any[]): DenormalizeNullable<S> | symbol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

type AbstractInstanceType<T> = T extends new (...args: any) => infer U ? U : T extends {
prototype: infer U;
} ? U : never;
Expand Down Expand Up @@ -72,14 +81,6 @@ type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S e
interface EntityMap<T = any> {
readonly [k: string]: EntityInterface<T>;
}
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface SnapshotInterface {
readonly fetchedAt: number;
Expand Down
17 changes: 9 additions & 8 deletions website/src/components/Playground/editor-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ type EntityFields<U> = {
readonly [K in keyof U as U[K] extends (...args: any) => any ? never : K]?: U[K] extends number ? U[K] | string : U[K] extends string ? U[K] | number : U[K];
};

type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

type AbstractInstanceType<T> = T extends new (...args: any) => infer U ? U : T extends {
prototype: infer U;
} ? U : never;
Expand Down Expand Up @@ -76,14 +85,6 @@ type NormalizeNullable<S> = S extends EntityInterface ? string | undefined : S e
interface EntityMap<T = any> {
readonly [k: string]: EntityInterface<T>;
}
type SchemaArgs<S extends Schema> = S extends EntityInterface<infer U> ? [EntityFields<U>] : S extends ({
queryKey(args: infer Args, ...rest: any): any;
}) ? Args : S extends {
[K: string]: any;
} ? ObjectArgs<S> : never;
type ObjectArgs<S extends Record<string, any>> = {
[K in keyof S]: S[K] extends Schema ? SchemaArgs<S[K]> : never;
}[keyof S];

interface SnapshotInterface {
readonly fetchedAt: number;
Expand Down

0 comments on commit b6298e7

Please sign in to comment.