-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
implicitly 'any' type error despite no circularity in assignment and being assigned a template literal #54790
Comments
Possible red herrings removed: function uniqueID (id: string | number, seenIDs: object) {
id = 'a';
for (let i = 1; i < 3; i++) {
const newID = `${id}`;
if (newID in seenIDs) { }
}
} |
Can be simplified even further: function uniqueID (id: string | number, seenIDs: object) {
id = 'a';
for (let i = 1; i < 3; i++) {
const newID = id;
if (newID in seenIDs) { }
}
} |
The change between origin/release-4.2 and origin/release-4.5 occurred at e064817. |
I'm not sure how easy this is going to be to fix. It looks like the circularity is as follows, using @Andarist 's example:
|
This is the same issue as the mentioned #48708 . This manifestation here is somewhat easy to get fixed (see my PR here) but that other one (and likely many others like it) are not as simple. My fix is somewhat targeted and a more general fix could just fix all issues at once but I don't know how to prepare a more general fix and the proposed one still feels like an improvement from the usability point of view π |
@Andarist good to see the PR that fixes this. I have a question from curiosity, a desire to understand. Answer only if it's easy and you can spare a minute. Since the loop has no other assignment to Likewise I don't understand why declaring |
Bug Report
π Search Terms
π Version & Regression Information
This changed between versions 4.3.5 and 4.4.2
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
const newID = `${id}-${i}`
yields error:'newID' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
π Expected behavior
const newID = `${id}-${i}`
has no error andnewID
has inferred type string:anyToString
proof in playground link and code below.π€ Some Analysis
Alternate versions to help isolate the bug
𧬠Possibly Related Bugs / Duplicates
Three other open issues i found have similar behavior:
undefined
ornull
removed from typeTwo of them have different "blame" changes. The third may have been introduced by the same change, but it makes some addition claims, and does not show the issue with template literals this issue does.
The text was updated successfully, but these errors were encountered: