Skip to content

Commit

Permalink
feat: typescript helper to make proxy with method intellisense better
Browse files Browse the repository at this point in the history
  • Loading branch information
pleb committed Aug 5, 2022
1 parent a5ac9a8 commit e40afbe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/data-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export abstract class DataBuilder<T> {
}
}

type WithMethods<T extends object, TBuilder> = {
[K in keyof T as K extends string ? `with${Capitalize<K>}` : never]-?: (d: T[K]) => WithMethods<T, TBuilder> & TBuilder
} & TBuilder
type WithMethods<T extends object, TBuilder> = CoerceIntellisense<
{
[K in keyof T as K extends string ? `with${Capitalize<K>}` : never]-?: (d: T[K]) => WithMethods<T, TBuilder> & TBuilder
} & TBuilder
>

export type CoerceIntellisense<T> = T extends infer O ? { [K in keyof O]: O[K] } : never

const proxyHandler = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit e40afbe

Please sign in to comment.