Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Satoshi committed Jan 2, 2024
1 parent ee54618 commit a8a8c50
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Option<TSchema extends BaseSchema, TRelation extends BaseRelation<TSchema>>
: K]: unknown
})[]
expand?: Expand<TSchema, TRelation, Related<TSchema, TRelation, TSchema[Key]>>[]

sort?: '@random' | `${'' | '+' | '-'}${keyof TSchema[Key] & string}`
filter?: string
requestKey?: string
Expand All @@ -31,21 +32,37 @@ type Expand<
> = {
[Key in TKey]: {
key: Key
fields?: Exclude<TRelation[Key], undefined> extends Array<infer U> | infer U
fields?: Required<TRelation>[Key] extends Array<infer U>
? (keyof {
[K in keyof U & string as U[K] extends string
? `${K}${'' | Modifier}`
: K]: unknown
})[]
: never
// fields?: Exclude<TRelation[Key], undefined> extends Array<infer U> | infer U
// ? (keyof U)[]
// : never
expand?: Exclude<TRelation[Key], undefined> extends
| Array<infer U extends TSchema[keyof TSchema]>
| infer U extends TSchema[keyof TSchema]
: (keyof {
[K in keyof TRelation[Key] & string as TRelation[Key][K] extends string
? `${K}${'' | Modifier}`
: K]: unknown
})[]
expand?: Required<TRelation>[Key] extends Array<infer U extends TSchema[keyof TSchema]>
? Expand<TSchema, TRelation, Related<TSchema, TRelation, U>>[]
: never
: Required<TRelation>[Key] extends infer U extends TSchema[keyof TSchema]
? Expand<TSchema, TRelation, Related<TSchema, TRelation, U>>[]
: never

// the following is correct syntax and passes tests, but fails at build step
// infer within union doesn't seem to work for whatever reason
// fields?: Required<TRelation>[Key] extends Array<infer U> | infer U
// ? (keyof {
// [K in keyof U & string as U[K] extends string
// ? `${K}${'' | Modifier}`
// : K]: unknown
// })[]
// : never
// expand?: Required<TRelation>[Key] extends
// | Array<infer U extends TSchema[keyof TSchema]>
// | infer U extends TSchema[keyof TSchema]
// ? Expand<TSchema, TRelation, Related<TSchema, TRelation, U>>[]
// : never
}
}[TKey]

Expand All @@ -60,7 +77,7 @@ type BackRelation<TSchema, TRelation, T extends TSchema[keyof TSchema]> = keyof
? Key
: never
: never
: never]: {}
: never]: unknown
} &
keyof TRelation

Expand All @@ -69,7 +86,6 @@ type ResponseType<
TRelation extends BaseRelation<TSchema>,
TOption extends Option<TSchema, TRelation>,
_Obj = TSchema[TOption['key']]
// > = TOption['fields'] extends Array<infer Fields extends keyof _Obj>
> = TOption['fields'] extends Array<infer U extends string>
? RemoveModifier<U> extends infer Fields extends keyof _Obj
? Pick<_Obj, Fields> & ProcessExpandArray<TSchema, TRelation, TOption['expand']>
Expand Down Expand Up @@ -131,10 +147,8 @@ type ProcessSingleExpand<
TSchema extends BaseSchema,
TRelation extends BaseRelation<TSchema>,
TExpand extends Expand<TSchema, TRelation, keyof TRelation>,
_Obj = Exclude<TRelation[TExpand['key']], undefined> extends Array<infer U> | infer U
? U
: never,
_IsToMany extends boolean = Exclude<TRelation[TExpand['key']], undefined> extends Array<unknown>
_Obj = Required<TRelation>[TExpand['key']] extends Array<infer U> | infer U ? U : never,
_IsToMany extends boolean = Required<TRelation>[TExpand['key']] extends Array<unknown>
? true
: false
> = TExpand['fields'] extends Array<infer U extends string>
Expand Down

0 comments on commit a8a8c50

Please sign in to comment.