Comments (6)
Please see #33191 and #42529. The behavior change in 5.4 is likely attributed to #56753. It is indeed somewhat interesting that the tooltip does show a type other than any
.
from typescript.
I'm fixing the weird inconsistent quick info display here: #59075
from typescript.
Please see #33191 and #42529. The behavior change in 5.4 is likely attributed to #56753. It is indeed somewhat interesting that the tooltip does show a type other than
any
.
Those issues look similar but I'm not sure the root cause is the same. The supposed circularity in my repro code is being caused by an empty if statement which is essentially dead code here. I assume it's narrowing something internally but given that it's not affecting the control flow at all (can be removed with zero consequences to the runtime), I don't see a good reason for this narrowing to be occurring. (Well, in the code that sparked the issue the if statement is not exactly dead code, but it's still unrelated to the variable that's getting the error.)
I'm fixing the weird inconsistent quick info display here: #59075
Doesn't that make it worse, though? The problem is in the extraneous error here, the tooltip has the correct type...
from typescript.
The supposed circularity in my repro code is being caused by an empty if statement which is essentially dead code here
It requests type of test
which in turn depends on the type of alsoChat
. That's how the circularity happens here. I agree that it's weird that some very similar cases work without running into circularity.
Doesn't that make it worse, though? The problem is in the extraneous error here, the tooltip has the correct type...
The tooltip has the correct type somewhat accidentally here. CheckMode.TypeOnly
was introduced to suppress comparability errors when dealing with intermediate types created during control flow analysis. Those errors that were suppressed by that PR didn't affect the control flow analysis at all. So it was OK to suppress them.
An encountered circularity returns any
type and that very much can propagate through the types computed during control flow analysis. That's why I think it wouldn't be good to suppress this error here in a similar way.
That said, this alternative patch doesn't change anything in the existing test suite and it "fixes" your particular circularity issue:
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index a965c51d22..640a0216c5 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -12055,6 +12055,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
return errorType;
}
+ if (checkMode && checkMode & CheckMode.TypeOnly) {
+ return anyType;
+ }
return reportCircularityError(symbol);
}
let type: Type;
@@ -12137,6 +12140,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
return type;
}
+ if (checkMode && checkMode & CheckMode.TypeOnly) {
+ return anyType;
+ }
return reportCircularityError(symbol);
}
return type;
But despite that, I think it's rather risky to allow this to propagate freely because the result propagates. Similarly, getTypeOfExpression
sets NodeFlags.TypeCached
on the node but in this scenario the type wouldn't actually be cached! That's just a different bug waiting to happen somewhere.
I also checked that it wouldn't have a perceivable bad impact on this scenario with an auto type:
declare const line: string;
let test;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (test === char) {}
const alsoChar = char;
test = alsoChar;
}
FWIW, I'm not saying that the circularity avoidance couldn't be improved for some of those cases. I feel like the change I proposed is good regardless of that.
from typescript.
#56753 is being superceded by #59183. This is a true circularity for basically the same reason as #33191 (comment).
from typescript.
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- Implement Interface Quick Fix generates duplicate declarations
- Inconsistent type validation: Different result depending on inline defined and executed function and declared and executed function HOT 17
- Variance annotations are not allowed in type aliases for intersections HOT 5
- No error or warning when assigning a constant to a constant but crash when run HOT 4
- Add support for Iterator Helpers (now stage 3) HOT 7
- Inconsistency between element access and object destruction HOT 1
- the union type bug? HOT 2
- Broken type inference for union of function and object HOT 2
- Symbol = LiveSymbol | DeadSymbol HOT 5
- compilerOptions.plugins accepts missing plugins without any logging or error information HOT 1
- Type inference considers only type amendments (if any are present), ignoring original typings HOT 4
- `satisfies` for return types HOT 5
- Type name in @throws not rendered as a link HOT 2
- Add organize imports presets
- Inconsistency between destructuring and object access in filter-narrowing. HOT 2
- autoimports crashes with aliased export
- Anonymous Function Type Not Constraining Object Return Value HOT 4
- Printer introduces syntax error into .tsx files
- Empty class type is satisfied by literally anything HOT 4
- The behavior of class Parameter Properties changes with the es target HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.