"implicit any" where circularity is trivially resolvable
See original GitHub issueBug 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:
- Created a year ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.