Skip to content

Auto-import from transitive dependency should work when existing import is present #59487

@arogg

Description

@arogg

🔎 Search Terms

import suggest resolve package.json subfolder paths workspace

🕗 Version & Regression Information

  • I tested this in multiple versions of typescript and the behavior always seems to be the same. I search google a lot. I found information about package.json imports property, and also types, typeRoots and paths property of tsconfig compilerOptions. I tried several things and nothing quite seems to fit.

⏯ Playground Link

No response

💻 Code

import React from "react"

useEffect() // ctrl-dot on this does not trigger the correct suggestion, if the relevant package.json is in a subfolder. even if the npm package exists in the root node_modules folder!

🙁 Actual behavior

pressing ctrl-dot on "useEffect" does not trigger a suggestion to import useEffect from the react package

🙂 Expected behavior

I expect the import suggestion to be shown, since npm indeed installs all package into the root folder, even if the package.json is in a subfolder. And it does compile and run OK if I write the import manually. But I am tired of writing imports manually.

Additional information about the issue

  • Why I need this: I have a submodule that I include as npm workspace in each of my repositories. The dependecies are only declared in package.json in my submodule. This avoids the need to declare the same dependencies in each of my projects
  • if this cannot be solved any other way, may I ask if there is a way to write some sort of typescript plugin that will recognise the package.json in my submodule to determine relevant import suggestions?

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions