Skip to content

How do I actually use a locally defined provider without contributing it to unpic? #169

Open

Description

@yacoob

I'm about 80% sure this is not an actual bug, but rather the fact that my knowledge of typescript is very patchy. Please bear with me :)

context: I wanted to add my own local provider to unpic. I have an endpoint that produces thumbnails on the fly, accepting just width and height from the url and rescaling the image. In prod, my images live on imagekit; this provider would handle things in the dev environment.

I've followed the instructions and made my own subclass of Operations, Options, generator and parser for Operations. I'm struggling with defining an URLExtractor<"local">, as the parametrized type is the ImageCdn union defined in unpic itself. I can't seem to be able to modify it via typescript module augmentation - I'm either using it incorrectly or there's something missing.

Would you please be able to add a minimal example of this to the documentation? Or add it here, and I'll happily update the docs :)

Thanks!

Activity

  1. yacoob commented on Feb 8, 2025

    @yacoob
    Author

    Judging by this documentation I can't add to a type alias via module augmentation. Which means I can't add to ImageCdn. Am I reading things correctly?

  2. PoSayDone commented on Apr 25, 2025

    @PoSayDone

    I'm also interested in this

  3. lesofl commented on Jan 11, 2026

    @lesofl

    Any update on this?

    I've tried for a few hours to try and get around this limitation and defined my own set of CdnOperations and CdnOptions but this function requires the typeto be one of the hardcoded values inside types.ts which seems incredibly frustrating.

    export const transform: URLTransformer<"example-cdn"> =
      createExtractAndGenerate(extract, generate);
    

    The docs mention following the contributing guide to implement a private transformer but this seems virtually impossible since a lot of the types that need to be configured are hard-coded into the library itself.

    I am really looking for something simple that allows simple manipulation of the URL similar to one offered by NextJS which can be found here: https://nextjs.org/docs/app/api-reference/components/image#loader.

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