harlan-zw / nuxt-site-config

Unifying site config with powerful and flexible APIs, for module authors and users.
https://nuxtseo.com/site-config
61 stars 3 forks source link

Return type `any` in type declaration files of distributed package #10

Closed toto6038 closed 6 months ago

toto6038 commented 7 months ago

Describe the bug

Description

In the distributed package of release v1.6.6, some function signatures have any return type.

Details

For source @/packages/module/src/runtime/composables/utils.ts https://github.com/harlan-zw/nuxt-site-config/blob/b57f7ddb92d666fab82393dcb0aa6d4bb5a8834a/packages/module/src/runtime/composables/utils.ts#L28-L41

In Visual Studio Code, as the inlay hint shows that it's possible to infer the implicit return type. I have confirmed that TypeScript version used in the editor is 5.2.2 that is consistent with the dependency.

image

But in the generated type declaration @/packages/module/dist/runtime/composables/utils.d.ts

SCR-20231205-kayc

The return type becomes any.

I'm not sure whether the problem is caused by @unjs/mkdist which is used by @nuxt/module-builder under the hood to generate type declaration files.

Solution

Mark return type explicitly.

Modified source

image

Generated type declaration

image

Reproduction

No response

System / Nuxt Info

- Operating System: `Darwin`
- Node Version:     `v18.18.2`
- Nuxt Version:     `3.8.2`
- CLI Version:      `3.10.0`
- Nitro Version:    `2.8.0`
- Package Manager:  `pnpm@8.10.2`
- Builder:          `-`
- User Config:      `-`
- Runtime Modules:  `-`
- Build Modules:    `-`
harlan-zw commented 6 months ago

Thank you for this issue @toto6038

I've added explicit return types for all of these functions, hopefully, this resolves it for you (available in v1.6.7).

Let me know if you still have issues though.