-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
tsc -b incorrectly succeeds when there is a problem introduced by a transitive dependency #46153
Comments
This does look like a bug, but it also sounds like there may be a misconception that |
"include": [
"A.ts"
] And if we remove
To me, this suggests that the import statement |
This is... surprising to me 😅 Could be a clue as to what’s going on. |
Your hypothesis sounds plausible—it certainly sounds like the transitive project reference connecting |
Multiple members of my team have reported incorrect results when running |
There are a lot of commits on 21 Jun 2019. I think this was before we started squashing PRs into a single commit. The PRs that are likely relevant are #32027 is a really simple bug fix. In I'll need to repro this myself, but from the commentary above on previous investigation, it sounds like maybe |
This issue is quickly becoming detrimental to productivity in the project that I work on. Are there any updates on timeline here? When making changes in a project |
@RyanCavanaugh @sandersn - Anyway we elevate the priority of the bug, and the timing of the fix. It's really causing major problems for our project. Thank you! |
I think this is working as intended. |
If the reference is not transitive (which was my original understanding), why does |
Thanks, I was unaware of the design decision in #30608 (comment)
Does this mean we are supposed to list all transitive dependencies explicitly at each level in order to achieve accurate type-checking behavior? For instance, in the example at the top of the page, projectA would change from: "references": [
{
"path": "../projectB"
}
] to "references": [
{
"path": "../projectB",
"path": "../projectC"
}
] In practice, our project has transitive dependencies around 10 layers deep, so each level should list everything?
That would certainly help us ensure we didn't forget to list a transitive dependency as a direct dependency. |
By having project reference, you are telling that any change to these project can affect the project. So it depends on your granularity of the project and what you want the distiction be |
@sheetalkamat I still think #46153 (comment) either sounds like a bug or (more likely) I’m still not understanding something. @samreid the way I have always set up project references is if I import directly from another project (as you imported projectC from projectA in your example), I list projectC as a reference of projectA. On the other hand, if I use exports from projectC only indirectly through projectB, I only list projectB as a reference of projectA. |
Even if you are not directly importing projectC, projectB's types could depend on projectA(and you might not be using those types) in that case your program still needs projectC |
Ah, right, the rootDir restriction only applies to .ts files, since it’s about the output directory structure. That makes sense. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
It would be really helpful to have more support from the compiler for making sure project references are set up in a way that will result in correct caching behavior from We recently migrated to project references, and we're now running into some issues with incorrect caching. I was not previously aware of the requirement to list transitive dependencies in project references in order for build caching to be correctly invalidated. I assumed that if my project type checked, then the references must be set up correctly. If it's too disruptive to make it an error to fail to list transitive dependencies in project references, perhaps the build caching system should be updated to invalidate its cache correctly without having references to transitive dependencies explicitly listed. |
Bug Report
project references
transitive
dependency
stale
🕗 Version & Regression Information
The incorrect behavior was observed in many versions since then, including:
⏯ Playground Link
Reproducing the problem requires transitive project references, and running
tsc -b
from the command line, so I don't believe it can be done in the TypeScript playground.💻 Code
My team observed that
tsc -b
can incorrectly succeed when a problem is introduced by a transitive dependency. In fact,tsc -b
can give two different results (type check passes or type check fails) for the same codebase. We created a self-contained reproducible example to demonstrate the problem. This creates 3 projects using project references, where project A depends on project B and that, in turn, depends on project C. There is one TypeScript file in project A, none in B and one in C.Step 1: Create the following 5 files, distributed into directories
projectA/
,projectB/
andprojectC/
.Step 2: clean and build project A
The clean step is not necessary on your first run, but we include it here in case you want to run through the steps again.
In this case, the expected result is the same as the actual result, which is a build failure with this message:
Step 3: Fix the error by updating C.ts.
In C.ts, change
name: string;
toname: any;
Step 4: build project A
Again, the expected result matches the actual result.
tsc
succeeds with no output.Step 5. Reintroduce the problem in C.ts
In C.ts, change
name: any;
back toname: string;
Step 6. Build Project A
🙁 Actual behavior
There is no output from
tsc
because the type check and build passes successfully. This is incorrect because there isa type error because
string
does not have a methodarbitraryFakeMethod
. Note that Step 6 is building the same code as in Step 2. However, in Step 2, the type error is correctly identified, but in Step 6 the type error is missed.🙂 Expected behavior
Step 6 should produce the following error (as it correctly did in Step 2):
Note that changing project A to depend on C directly (not through B) correctly identifies the problem when running
tsc -b
in project A, so this bug does require the intermediate transitive dependency. TypeScript correctly caught this error through Version 3.6.0-dev.20190621 (good), but started missing it in 3.6.0-dev.20190622 (bad). For completeness, we will mention that we first detected the problem when projectC was *.js code, so it seems to affect both *.ts and *.js dependencies. This problem was discovered in phetsims/chipper#1067The text was updated successfully, but these errors were encountered: