Skip to content

Combine factories with optional field #63

Description

@jagers

Hello,

I'm trying to combine factories for an interface that has an optional field and I'm running into a typescript error.
Using the following example:

const softDelete = Sync.makeFactory({
    isDeleted: false,
})
interface Post {
    content?: string
    isDeleted: boolean
}
const postFactory: Sync.Factory<Post> = Sync.makeFactory({
    content: 'lorem ipsum',
}).combine(softDelete)

TS compilation results in:

TS2322: Type 'Factory<{ content: string; } & { isDeleted: boolean; }, "isDeleted" | "content">' is not assignable to type 'Factory<Post, keyof Post>'.
  The types of 'builder.isDeleted' are incompatible between these types.
    Type 'boolean | Generator<boolean> | Derived<{ content: string; } & { isDeleted: boolean; }, boolean>' is not assignable to type 'boolean | Generator<boolean> | Derived<Post, boolean>'.
      Type 'Derived<{ content: string; } & { isDeleted: boolean; }, boolean>' is not assignable to type 'boolean | Generator<boolean> | Derived<Post, boolean>'.
        Type 'Derived<{ content: string; } & { isDeleted: boolean; }, boolean>' is not assignable to type 'Derived<Post, boolean>'.
          Type 'Post' is not assignable to type '{ content: string; } & { isDeleted: boolean; }'.

Am I missing something or is this a bug?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions