Skip to content

Import suggestions for referenced project include files in outDir #40791

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 4.0.3

Search Terms: auto imports

Code

Reduced test case: https://github.com/OliverJAsh/ts-project-references-playground/tree/imports-bug. Below I have inlined the code from this repository.

shared/tsconfig.json:

{
  "compilerOptions": {
    "composite": true,
    "outDir": "../target-tsc-build/",
    "rootDir": ".."
  },
  "files": ["./main.ts"]
}

shared/main.ts:

export const shared = 1;

webpack/tsconfig.json:

{
  "compilerOptions": {
    "outDir": "../target-tsc-build/",
    "rootDir": "..",
    "baseUrl": "./",
    "paths": {
      "shared/*": ["../shared/*"]
    }
  },
  "files": ["a.ts", "b.ts"],
  "references": [
    {
      "path": "../shared/tsconfig.json"
    }
  ]
}

webpack/a.ts:

import { shared } from "shared/main";

console.log(shared);

webpack/b.ts:

console.log(shared);

Expected behavior:

When I open webpack/b.ts

  • TypeScript should suggest importing symbol shared from shared/main. There should be no other suggestions.
  • Activating auto import should result in:
    import { shared } from "shared/index";
    
    console.log(shared);

Actual behavior:

  • TypeScript suggests importing symbol shared from ../target-tsc-build/shared/main (the file in outDir) and then shared/main.
    image
  • Activating auto import results in:
    import { shared } from "../target-tsc-build/shared/main";
    
    console.log(shared);
    The outDir file is the primary suggestion, therefore it is used for auto import:
    image

Import suggestions should never be provided for compiled files—only source files.

Note I also tried adding exclude: ["./target-tsc-build/"] and "declarationMaps": true to all configs, but that didn't seem to help.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions