Skip to content

Missing path completions for exports field patterns when relying on sibling .d.ts file lookup #54330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
emmatown opened this issue May 20, 2023 · 1 comment · Fixed by #54869
Assignees
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Fix Available A PR has been opened for this issue

Comments

@emmatown
Copy link
Contributor

Bug Report

🔎 Search Terms

path completions package.json exports pattern wildcard

🕗 Version & Regression Information

This is the behavior in every version I tried, and none of the FAQ entries are relevant. #49644 added path completions for exports fields patterns but it relies on pointing to a .d.ts file directly.

⏯ Playground Link

This can't be reproduced in the playground since it relies on a package.json.

💻 Code

As a failing fourslash test:

/// <reference path="fourslash.ts" />

// @module: nodenext

// @Filename: /node_modules/foo/package.json
//// {
////   "name": "foo",
////   "exports": {
////     "./*": "./dist/*.js"
////   }
//// }

// @Filename: /node_modules/foo/dist/blah.d.ts
//// export const blah = 0;

// @Filename: /index.mts
//// import { } from "foo//**/";

verify.completions({
  marker: "",
  isNewIdentifierLocation: true,
  exact: [
    { name: "blah", kind: "script", kindModifiers: "" },
  ]
});

It works if you update the package.json to this:

{
  "name": "foo",
  "exports": {
    "./*": {
      "types": "./dist/*.d.ts",
      "default": "./dist/*.js"
    }
  }
}

🙁 Actual behavior

Path completions are missing for patterns in package.json exports fields when pointing to a .js/.mjs/.cjs file and relying on TypeScript to load the sibling .d.ts/.d.mts/.d.cts file.

🙂 Expected behavior

Path completions shouldn't be affected by whether you're relying on sibling lookup or not, especially since the recommendation is to rely on it rather than use a types condition.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 23, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.2.0 milestone May 23, 2023
@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor and removed Needs Investigation This issue needs a team member to investigate its status. labels May 23, 2023
@andrewbranch
Copy link
Member

Thanks for the fourslash test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants