Extracting type from block results in "never", always (hehe)

default discord avatar
steveninety9 months ago
2
  • default discord avatar
    diesieben079 months ago
    Page['blocks']

    is an array, which has no overlap with

    { blockType: "collectionItems" }

    , that's why you get

    never

    .


    What you want is

    Page['blocks'][number]

    to get the elements of the array. This however doesn't work either, because

    Page['blocks']

    is optional. You can fix that with

    NonNullable

    :


    type Hero = Extract<NonNullable<Page['blocks']>[number], { blockType: "collectionItems" }>
  • default discord avatar
    steveninety9 months ago

    That answers my question, thanks for this typescript lesson 🙂

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.