question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"implicit any" where circularity is trivially resolvable

See original GitHub issue

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common “Bugs” That Aren’t Bugs and When and why are classes nominal?

⏯ Playground Link

Playground link with relevant code

💻 Code

class Foo {
  constructor(_provider: FooProvider) {}
}

interface FooProvider {
  getFoo(): Foo
}

class FooFactory {
  // 'getFoo' implicitly has return type 'any' because it does not have a
  // return type annotation and is referenced directly or indirectly in one of
  // its return expressions. (7023)
  getFoo() {
    // 'result' implicitly has type 'any' because it does not have a type
    // annotation and is referenced directly or indirectly in its own
    // initializer. (7022)
    const result = new Foo(this)
    return result
  }
}

🙁 Actual behavior

The type of the variable result, and thus the return type of FooFactory.getFoo, defaults to any. This is wrong, because result clearly has the type Foo regardless of the type of the argument to the Foo constructor.

Adding implements FooProvider to FooFactory does not help, which I also find a bit strange.

🙂 Expected behavior

The circularity should be resolved at the new Foo(this) expression, since calling this non-generic constructor can only result in one possible type, regardless of arguments.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Jul 8, 2022

If someone can make this work without making a bunch of other stuff (perf, maintainability, etc) worse they’re free to send a PR, but we don’t think that’s possible.

1reaction
MartinJohnscommented, Jul 8, 2022

That would require the compiler to perform type checks in two iterations (first inference, then the rest), which it currently not does. The issue exists for a long time already, and Ryan mentions the issue in this comment.

The best approach is really to just add a type annotation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is circular reasoning always a fallacy?
As long as all these things are actually equal, this reasoning is perfectly valid, if mindlessly trivial. There are two problems with circular...
Read more >
Fundamental Circularities in the Theory of Argumentation
Are these circularities really objectionable? Are they resolvable? If they are not, how can we live with them? It will be argued that...
Read more >
Modal Metaphysics | Internet Encyclopedia of Philosophy
(Impossible worlds facilitate the semantics of, for example, “Some round squares are round” or “Crazy people believe that some round squares exist.”) However, ......
Read more >
The incompleteness of an incompleteness argument - arXiv
set theory, always some highly uncommon notations to deal with encodings. ... by making explicit an assumption that was implicit before in the...
Read more >
Self-Reference - Stanford Encyclopedia of Philosophy
More precisely, it rests on an implicit assumption that any infinite ... such as Yablo's that do not rely on circularity and self-reference....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found