Skip to content

Intersecting types based on Generic types #3884

@c10b10

Description

@c10b10

Lets say I have an object type that represents the template of other more specific types. How does one define the more specific type so that the following usecase does not fail?

Here's a failing attempt:

type Data<T1> = {
  loading: boolean,
  error: string,
  fetch: (options: {
    update: (prevResult: T1, moreData: { moreResult: T1, moreVar: Object }) => Object
  }) => void
}

type SpecificData<T1> = Data<T1> & {
  items: Array<string>
}

const f = (data: SpecificData<SpecificData>) => ({
  data,
  loadMore: () => {
    data.fetch({
      update: (prevResult, { moreResult, moreVar }) => ({
        items: [...prevResult.items, ...moreResult.items]
      })
    })
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions