Repository navigation
fix(db): resolve Nuxt aliases in schema declarations - #954
Merged
Merged
Conversation
The declaration build ran tsc without the Nuxt aliases that the JS bundle uses, so aliased imports in schema files were typed `any` in @nuxthub/db. Closes #934 Amp-Thread-ID: https://ampcode.com/threads/T-01a1cfeb-885a-7730-904a-ed32f015a120
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
playground | c3bef3a | Commit Preview URL Branch Preview URL |
Nov 12 2026, 01:37 PM |
Draft
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
buildDatabaseSchemapassesnuxt.options.aliasto the JS bundle, but the declaration build runs tsc withtsconfig: falseand nopaths. A schema file that imports through a Nuxt alias, such as a layer'sorderstable importinguserfrom#auth/schema, works at runtime but getsanyin@nuxthub/db's types (user: One<any, true>).What changed
dtsstep now gets the same aliases as the JS bundle, as tsccompilerOptions.paths:aliasandalias/*for each one..js,.mjsor.cjs, the path without the extension is tried first, so tsc finds the.d.tsbeside it. This is what Nuxt's own tsconfig does. Given a path with an extension, tsc loads that exact file, and a.mjsfile isany. The original path stays as a fallback, for directories whose names end in.js.SCHEMA_TYPES_CACHE_VERSIONgoes to 2, so declarations cached with the old options are rebuilt.Evidence
New test
resolves Nuxt aliases in schema typesintest/database.schema-build.test.ts. It covers a file alias (.mjswith a.d.tsbeside it) and a directory alias (#shared/status).Before the fix, the generated
schema.d.mtswas:After the fix, the test passes, along with the rest of
database.schema-build.test.tsanddatabase.config.test.ts(53 tests).I also ran the reporter's repro with this branch linked in and the cache cleared, then ran
nuxt typecheck. Check 2 is the layer relation touser:@nuxtjs/better-authpatchordersRelations.userOne<any, true>One<"user", true>One<any, true>Note
The issue says the core change turns check 2 green on its own. I couldn't reproduce that, and the reporter's own patch didn't do it either when I tried.
@nuxtjs/better-authpoints#auth/schemaat a.mjsfile with no declarations beside it, so tsc has nothing to type it with. Fully fixing the repro also needs nuxt-modules/better-auth#506.ELI5
The database types are built by a separate step that didn't know the app's import shortcuts, so anything imported through a shortcut was typed as "anything". That step now gets the same shortcuts as the rest of the build.