-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
references
are not inherited in tsconfig.json
#27098
Comments
This is the intended behavior but we need to document it |
@RyanCavanaugh, what was the reasoning behind disallowing inheritance of the "reference" setting? In the old IMO that seemed to be the outcome of least surprise. |
I tried to use inheritance of |
@RyanCavanaugh, still curious about the reasoning behind this design decision. I have a use case where I need to switch the module system from While there may be reasons for not wanting to extend this attribute, I think there are also legitimate reasons for doing so. Copying the references is error-prone, people forget about it. Maybe you can find a way to allow this in a future version. Thanks :) |
For some hierarchy
If references are inherited, then the first scenario is impossible to do. If they're not inherited, then you can pick which you mean from |
Got caught by this. In my setup I have: I don't understand why you can't, in an inherited tsconfig, just set the 'references' to an empty array in order to override the inheritance (completely). perhaps introducing a keyword to signal intent might be the way to go? i.e.
|
@RyanCavanaugh Rather than having an extra tag in references, why not optionally allow references to be placed into a separate json file and then be refer to it in the config? That way cases where people specifically want to list their references in a single location and share those references between two or more tsconfig.json files, they can do so without impacting those that might be affected the proper functioning of your first scenario above? |
@RyanCavanaugh Thanks for explanation, but I'm not sure if expected behavior and explanation provided aligns with common understanding of what "extends" mean in scope of configuration. The example you've provided make perfect sense if A, B, C would be libraries and edges are Whereas, when it comes to configuration - at least pople in this thread - inheritance means "just" take all the props from parent config, so basic "public" inheritance like we experience with So, summarizing design you're referring IMHO conflicts with common understanding of inheritance in configuration systems. Is there chance to have workaround? (given that - assuming from your comment - current behavior is already set in stone). |
I support the opinion, that current inheritance model isn't optimal. Because tsconfig.json is a plain json file (very pity!), there is no sophisticated way to workaround it. Just for simply cases for monorepos I would like to promote my alpha set-project-references helper. It doesn't help with inheritance, but makes life with project references easier. |
^^ Documented this as it bit me hard tonight. |
In the handbook it says:
Following the principle of lease surprise, Regarding what Ryan said:
Is it still impossible if we allow
|
Surprised++ The hierarchy/hiding argument seems a bit weak to me. Let's make those edge cases not use inheritance and just copypasta rather than changing what inheritance means structurally. I am also trying to create a production build and avoid to compiling tests files that depend on test packages. If I exclude test files from my normal tsconfig that breaks other things (like IDEs) so I am attempting to write a |
Unfortunately, we need an additional `tsconfig.json` per `__tests__` directory to satisfy VS Code due to microsoft/vscode/#12463. I tried having these extend the `tsconfig.test.json` in their respective packages, but it turns out `references` are not inherited (see microsoft/TypeScript#27098).
I'll jump in this and bump this issue. I have a tsconfig.build.json to exclude test files from builds and expected references to inherit as this isn't clearly documented. It isn't particularly optimal to duplicate the references in tsconfig.json and tsconfig.build.json but seems like that's the only working solution currently? |
this is my unfortunate workaround for this issue: It would be really nice to get a real solution for this. const path = require("path");
const fs = require("fs");
const spawn = require("child_process").spawn;
const tsConfigPath = path.join(process.cwd(), "tsconfig.json");
const tsConfig = require(tsConfigPath);
tsConfig.exclude = tsConfig.exclude ?? [];
tsConfig.exclude.push("src/test");
const prodTsPath = "tsconfig.prod.json";
fs.writeFileSync(prodTsPath, JSON.stringify(tsConfig, null, 2));
const tscProcess = spawn("tsc", ["--build", prodTsPath], { cwd: process.cwd() });
tscProcess.stdout.pipe(process.stdout);
tscProcess.stderr.pipe(process.stderr);
tscProcess.on("close", (code) => {
fs.rmSync(prodTsPath);
setImmediate(process.exit(code));
}); |
seems to be best monorepo setup I have found to date for typescript. This would be amazing if fixed. Reference blog that refers to this bug -> https://blog.ah.technology/a-guide-through-the-wild-wild-west-of-setting-up-a-mono-repo-with-typescript-lerna-and-yarn-ed6a1e5467a |
This one just bit me hard. And since it has been this way for years there's no way to roll it back in. This is a real bummer because separate build/test/lint configs are more necessary than not, and generally they all extend a base config. Maybe the "extends" property can accept an object with an {
"extends": {
"path": "../path/to/project",
"includeReferences": true
}
} |
I have dozens of packages in my monorepo, and I want to exclude test files from my production builds. So I need dozens of Would definitely like to understand better why the references can't be inherited ... |
* update tsconfig configuration in `/model` * update tsconfig configuration in `/core` * update tsconfig configuration in `/chains` * update tsconfig configuration in `/adapters` * update tsconfig configuration in `shared` * update tsconfig configuration in `logging` * `packages/commonwealth` tsconfig update + copy `references` to build tsconfig (microsoft/TypeScript#27098) * specify tsconfig.build.json in references * discobot and snapshot tsconfig.build.json updates * remove test from includes (follow-up PR) * merge resolution * merge resolution * remove "test" from include in snapshot * leaner tsconfig --------- Co-authored-by: rotorsoft <rotorsoft@outlook.com>
* update tsconfig configuration in `/model` * update tsconfig configuration in `/core` * update tsconfig configuration in `/chains` * update tsconfig configuration in `/adapters` * update tsconfig configuration in `shared` * update tsconfig configuration in `logging` * `packages/commonwealth` tsconfig update + copy `references` to build tsconfig (microsoft/TypeScript#27098) * specify tsconfig.build.json in references * discobot and snapshot tsconfig.build.json updates * remove test from includes (follow-up PR) * merge resolution * merge resolution * remove "test" from include in snapshot * leaner tsconfig * remove `includes` from lib tsconfigs + fix `/adapters/test/` types --------- Co-authored-by: rotorsoft <rotorsoft@outlook.com>
* update tsconfig configuration in `/model` * update tsconfig configuration in `/core` * update tsconfig configuration in `/chains` * update tsconfig configuration in `/adapters` * update tsconfig configuration in `shared` * update tsconfig configuration in `logging` * `packages/commonwealth` tsconfig update + copy `references` to build tsconfig (microsoft/TypeScript#27098) * specify tsconfig.build.json in references * discobot and snapshot tsconfig.build.json updates * remove test from includes (follow-up PR) * merge resolution * merge resolution * remove "test" from include in snapshot * model test type fixes * leaner tsconfig --------- Co-authored-by: rotorsoft <rotorsoft@outlook.com>
* update tsconfig configuration in `/model` * update tsconfig configuration in `/core` * update tsconfig configuration in `/chains` * update tsconfig configuration in `/adapters` * update tsconfig configuration in `shared` * update tsconfig configuration in `logging` * `packages/commonwealth` tsconfig update + copy `references` to build tsconfig (microsoft/TypeScript#27098) * specify tsconfig.build.json in references * discobot and snapshot tsconfig.build.json updates * remove test from includes (follow-up PR) * merge resolution * merge resolution * remove "test" from include in snapshot * update discord-bot base tsconfig * last discord bot fixes * snapshot fixes * remove snapshot tsc-alias * clean snapshot dependencies * leaner tsconfig * move tsx to devDep --------- Co-authored-by: rotorsoft <rotorsoft@outlook.com>
I think this is dumb. Why have references at all! Instead just look at the node_modules folders and go up the tree like node does. Then all these workspaces would just work without having to manually add references or even worse add some huge library like Nx to manage it all. It is like they want to make it as complex as possible. |
Oh god... This should be implemented.. Any update on this is it considered or not? |
TypeScript Version: 3.1.0-dev.20180914
Search Terms: tsconfig.json extends references inheritance
It seems that the
references
key is not inherited via theextends
mechanism, which surprised me because the handbook doesn't mention anything special about it.Demo:
tsconfig.base.json
:tsconfig.doesnt-work.json
:Building
tsconfig.doesnt-work.json
doesn't build the reference:tsconfig.works-but-duplicates-references.json
:This is a correct build but I had to duplicate the
references
key:The text was updated successfully, but these errors were encountered: