Skip to content

Can tsserver support multiple tsconfig.json's per directory? #49190

Closed
@amybzhao

Description

@amybzhao

Suggestion

Allow tsserver to find and use tsconfig.json's not named "tsconfig.json", and choose between multiple tsconfig.json's in a directory if there's more than one (e.g. tsconfig.test.json, tsconfig.src.json)

This is similar to #32039 but not quite the same (I don't think that issue includes supporting use of multiple tsconfig.json's in a directory)

🔍 Search Terms

  • tsserver
  • tsconfig.json

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Today, tsserver seems to search specifically for the nearest tsconfig.json file. It'd be helpful if it could search for files named tsconfig*.json, and if there are multiple in the same directory then use their include/exclude settings to determine which to use for the opened file.

📃 Motivating Example

A common preference amongst devs at our company is to co-locate source files and test files in the same directory, e.g.:

  • design_system/
    • button.ts
    • button_test.ts

This makes it easy to see at a glance which src files are covered by tests and find the corresponding tests, and VSCode's new file nesting feature supports this setup nicely.

However, this does not play nicely with VSCode's built-in TS language service since tsserver looks specifically for the nearest file named tsconfig.json. If we were to add separate tsconfig.json's for tests vs source files (in case we wanted different compilation settings), and our directory looked like:

  • design_system/
    • button.ts
    • button_test.ts
    • tsconfig.json
    • tsconfig.test.json

tsserver would only find tsconfig.json and not tsconfig.test.json

💻 Use Cases

What do you want to use this for?

  • Enabling correct editor intellisense when co-locating the configuration for multiple related projects in the same directory

What workarounds are you using in the meantime?

  • Use a single tsconfig.json for all files in the directory for the editor, and generate separate ones on-the-fly at build time

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