core icon indicating copy to clipboard operation
core copied to clipboard

Export blob types

Open Barbapapazes opened this issue 1 year ago • 5 comments

Hello 👋,

Do you thing that the blob types, https://github.com/nuxt-hub/core/blob/main/src/runtime/server/utils/blob.ts#L734-L739, could be exported? This could be helpful.

I'm validating a file on the frontend using zod and then on the backend using ensureBlob and I want common size and format so I use variables. My issue is that I'm not able to correctly type theses variables for the ensureBlob because I do no have access to these types.

Barbapapazes avatar Jun 05 '24 06:06 Barbapapazes

Sounds good to me to export some of them yes, happy to open a PR?

atinux avatar Jun 05 '24 09:06 atinux

Hey,

I'm not sure how to solve this. When I take a look at other packages like nuxt/content or nuxt/fonts, they handle exported types differently. How should I proceed? Is there any recommended way?

Barbapapazes avatar Jun 05 '24 20:06 Barbapapazes

Would love to get your expertise on this @farnabaz

atinux avatar Jun 06 '24 00:06 atinux

So far I think the best way to expose types in modules is to create a types/index.ts file inside src directory and export it via module.ts. This way, users can import types easily via module package

import { type Foo } from `package`

As for nuxt/content, we discussed it and in next version types will be exposed from main package too.

Update: Seems that nuxt/image also do the same thing https://github.com/nuxt/image/blob/e7242fbc2bb37d484f1c903e8a28532973b11ddb/src/module.ts#L24

Update2: We can implement this in/after https://github.com/nuxt-hub/core/pull/138

farnabaz avatar Jun 11 '24 10:06 farnabaz

If you think you can do it in #130, let's go! Otherwise, I'll wait and make a PR using your advices!

Barbapapazes avatar Jun 11 '24 11:06 Barbapapazes

I believe this has been resolved now core/src/types/blob.ts at main · nuxt-hub/core

image.png

RihanArfan avatar Nov 10 '24 05:11 RihanArfan

Nice! Thanks!

Barbapapazes avatar Nov 20 '24 15:11 Barbapapazes