nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
802 stars 35 forks source link

The `type` inferences for `hubDatabase` and `hubKV` methods are gone #166

Closed ra-jeev closed 2 weeks ago

ra-jeev commented 2 weeks ago

Describe the bug Intellisense is not working for methods of hubDatabase and hubKV. Methods show up as type any.

Steps to reproduce

  1. Start with the latest starter template (with @nuxthub/core v0.6.14)
  2. Open the project in VSCode
  3. Go to the existing server api/routes and try to check the types of hubDatabase or hubKV methods; they show up as type any
  4. No such issue for hubBlob (as HubBlob type is defined in the same file)

Expected behavior The correct method signature should be displayed.

Possible Cause

HubKV and HubDatabase types are being imported from individual files instead of the index file. E.g. Current:

import type { HubKV } from '../../../../types/kv.js';

Should be:

import type { HubKV } from '../../../../types';
Atinux commented 2 weeks ago

Could you take a look at it @farnabaz ?

danielroe commented 2 weeks ago

I’ll take a look but this is likely a consequence's of better compilation in module builder. ideally you treat your runtime files separately from module - either locating types in the runtime, or importing from the module package name, not a relative import.

Barbapapazes commented 2 weeks ago

importing from the module package name

What do mean Daniel? 🤔

danielroe commented 2 weeks ago

@Barbapapazes opened a PR to show!

And thank you for your excellent PR migrating this module to use stub mode. I think that should enable writing some type tests to ensure something like this doesn't happen again.