Skip to content

Type issue related to auto import #1432

@kevinend51

Description

@kevinend51

Environment


  • Operating System: Linux
  • Node Version: v24.0.1
  • Nuxt Version: 4.1.0
  • CLI Version: 3.28.0
  • Nitro Version: 2.12.5
  • Package Manager: npm@11.3.0
  • Builder: -
  • User Config: compatibilityDate, devtools, modules, css, colorMode, echarts, ssr, nitro, test
  • Runtime Modules: @nuxt/ui@3.3.3, nuxt-echarts@1.0.0, @nuxt/eslint@1.9.0, @nuxt/icon@2.0.0, @nuxt/test-utils/module@3.19.2
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-9plprupi?file=test%2Fapp.nuxt.spec.ts

Describe the bug

For a regular nuxt project, directories such as server, app and shared have differenct tsconfig, which make type inference correct for auto import (e.g. ref). However, the standalone test directory does not have it's own tsconfig, thus auto imported stuff will cause type issue.

https://stackblitz.com/edit/github-9plprupi?file=test%2Fapp.nuxt.spec.ts

Take this for example. Assume components directory is configured with tsconfig, ref is auto imported there and the type would be correct. However, test is not config with specific tsconfig, thus useRef's return type would be incorrect - since ref's type is not resolved properly.

My solution is to put tests in different directory. For example, put server tests under server/__tests__, app test under app/__tests__, ... etc. But I think this issue may fixed from the test-utils side - may test util modify tsconfig under .nuxt folder, inject test directory into the includes section, so the type issue could be handled properly?

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions