Skip to content

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

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
5 tasks done
amybzhao opened this issue May 20, 2022 · 5 comments
Closed
5 tasks done

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

amybzhao opened this issue May 20, 2022 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@amybzhao
Copy link

amybzhao commented May 20, 2022

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
@RyanCavanaugh
Copy link
Member

We have an open suggestion for this somewhere but it's obviously very hard to find... 😅

@MartinJohns
Copy link
Contributor

@RyanCavanaugh Perhaps you mean #33094?

@RyanCavanaugh
Copy link
Member

@MartinJohns 🙏

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 20, 2022
@amybzhao
Copy link
Author

Oops 🤦‍♀️ that's actually the one I meant to link in the description when I wrote:

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)

Must've copy/pasted the wrong open tab's url!

I don't think just allowing us to configure using specific tsconfig.json's would solve our use case. e.g. if we configured tsserver to use files named tsconfig.src.json and tsconfig.test.json's, for a file in the same directory as both tsconfig.*.json's it would still have to determine which one to use for button.ts vs button_test.ts

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants