Skip to content

VSCode TypeScript project references resolve of duplicate filesΒ #48058

Closed as not planned
@xiaoxiangmoe

Description

@xiaoxiangmoe

Bug Report

πŸ”Ž Search Terms

VSCode, tsconfig ,project references

πŸ•— Version & Regression Information

  • TypeScript Version: 4.1.0-dev.20201020 (4.1.0-dev.20201019 works well)
  • VS Code Version: 1.64.2 (Universal)
  • OS Version: Darwin x64 21.2.0

⏯ Example repo

https://github.com/xiaoxiangmoe/typescript-project-reference-demo.git

πŸ’» Code

// tsconfig.json

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.test.json"
    },
  ]
}

// tsconfig.app.json

{
  "include": ["src/**/*"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "moduleResolution": "Node",
    "composite": true,
    "target": "ESNext",
    "noEmit": true,
    "strict": true,
    "lib": ["DOM", "ESNext"],
    "types": []
  }
}

// tsconfig.test.json

{
  "extends": "./tsconfig.app.json",
  "exclude": [],
  "compilerOptions": {
    "types": ["node"]
  }
}

// src/components/Foo.ts

export type FooProps = { a: number };
export function Foo(props: FooProps) {
  return null;
}
/**
 * this file is included in both `tsconfig.app.json` and `tsconfig.test.json`
 * 
 * So we should follow the order of `references` in `tsconfig.json`
 * 
 * `tsconfig.app.json` comes before `tsconfig.test.json`, so we should use config file `tsconfig.app.json` in vscode
 * 
 */
const cwd = process.cwd()

πŸ™ Actual behavior

I think const cwd = process.cwd() should has an Error.

Because file src/components/Foo.ts are included in tsconfig.app.json. So it has not include type @types/node.

πŸ™‚ Expected behavior

const cwd = process.cwd() has no Error.

File src/components/Foo.ts is included in both tsconfig.app.json and tsconfig.test.json. VSCode search references field and use the last item of references β€”β€” tsconfig.test.json. So it has no error.

I think we should use first reference. I remember that earlier versions of vscode did this too. I want to know why VSCode/TS change it to use last reference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions