-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Report circular type inference errors with -noImplicitAny #665
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/baselines/reference/implicitAnyFromCircularInference.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
==== tests/cases/compiler/implicitAnyFromCircularInference.ts (9 errors) ==== | ||
|
||
// Error expected | ||
var a: typeof a; | ||
~ | ||
!!! 'a' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation. | ||
|
||
// Error expected on b or c | ||
var b: typeof c; | ||
var c: typeof b; | ||
~ | ||
!!! 'c' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation. | ||
|
||
// Error expected | ||
var d: Array<typeof d>; | ||
~ | ||
!!! 'd' implicitly has type 'any' because it is referenced directly or indirectly in its own type annotation. | ||
|
||
function f() { return f; } | ||
|
||
// Error expected | ||
function g() { return g(); } | ||
~ | ||
!!! 'g' 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. | ||
|
||
// Error expected | ||
var f1 = function () { | ||
~~~~~~~~~~~~~ | ||
return f1(); | ||
~~~~~~~~~~~~~~~~ | ||
}; | ||
~ | ||
!!! Function 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. | ||
|
||
// Error expected | ||
var f2 = () => f2(); | ||
~~~~~~~~~~ | ||
!!! Function 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. | ||
|
||
// Error expected | ||
function h() { | ||
~ | ||
!!! 'h' 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. | ||
return foo(); | ||
function foo() { | ||
return h() || "hello"; | ||
} | ||
} | ||
|
||
interface A { | ||
s: string; | ||
} | ||
|
||
function foo(x: A): string { return "abc"; } | ||
|
||
class C { | ||
// Error expected | ||
s = foo(this); | ||
~~~~~~~~~~~~~~ | ||
!!! 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. | ||
} | ||
|
||
class D { | ||
// Error expected | ||
get x() { | ||
~~~~~~~~~ | ||
return this.x; | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
} | ||
~~~~~ | ||
!!! 'x' 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. | ||
} | ||
|
103 changes: 103 additions & 0 deletions
103
tests/baselines/reference/implicitAnyFromCircularInference.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
//// [implicitAnyFromCircularInference.ts] | ||
|
||
// Error expected | ||
var a: typeof a; | ||
|
||
// Error expected on b or c | ||
var b: typeof c; | ||
var c: typeof b; | ||
|
||
// Error expected | ||
var d: Array<typeof d>; | ||
|
||
function f() { return f; } | ||
|
||
// Error expected | ||
function g() { return g(); } | ||
|
||
// Error expected | ||
var f1 = function () { | ||
return f1(); | ||
}; | ||
|
||
// Error expected | ||
var f2 = () => f2(); | ||
|
||
// Error expected | ||
function h() { | ||
return foo(); | ||
function foo() { | ||
return h() || "hello"; | ||
} | ||
} | ||
|
||
interface A { | ||
s: string; | ||
} | ||
|
||
function foo(x: A): string { return "abc"; } | ||
|
||
class C { | ||
// Error expected | ||
s = foo(this); | ||
} | ||
|
||
class D { | ||
// Error expected | ||
get x() { | ||
return this.x; | ||
} | ||
} | ||
|
||
|
||
//// [implicitAnyFromCircularInference.js] | ||
// Error expected | ||
var a; | ||
// Error expected on b or c | ||
var b; | ||
var c; | ||
// Error expected | ||
var d; | ||
function f() { | ||
return f; | ||
} | ||
// Error expected | ||
function g() { | ||
return g(); | ||
} | ||
// Error expected | ||
var f1 = function () { | ||
return f1(); | ||
}; | ||
// Error expected | ||
var f2 = function () { return f2(); }; | ||
// Error expected | ||
function h() { | ||
return foo(); | ||
function foo() { | ||
return h() || "hello"; | ||
} | ||
} | ||
function foo(x) { | ||
return "abc"; | ||
} | ||
var C = (function () { | ||
function C() { | ||
// Error expected | ||
this.s = foo(this); | ||
} | ||
return C; | ||
})(); | ||
var D = (function () { | ||
function D() { | ||
} | ||
Object.defineProperty(D.prototype, "x", { | ||
// Error expected | ||
get: function () { | ||
return this.x; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return D; | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @noimplicitany: true | ||
// @target: es5 | ||
|
||
// Error expected | ||
var a: typeof a; | ||
|
||
// Error expected on b or c | ||
var b: typeof c; | ||
var c: typeof b; | ||
|
||
// Error expected | ||
var d: Array<typeof d>; | ||
|
||
function f() { return f; } | ||
|
||
// Error expected | ||
function g() { return g(); } | ||
|
||
// Error expected | ||
var f1 = function () { | ||
return f1(); | ||
}; | ||
|
||
// Error expected | ||
var f2 = () => f2(); | ||
|
||
// Error expected | ||
function h() { | ||
return foo(); | ||
function foo() { | ||
return h() || "hello"; | ||
} | ||
} | ||
|
||
interface A { | ||
s: string; | ||
} | ||
|
||
function foo(x: A): string { return "abc"; } | ||
|
||
class C { | ||
// Error expected | ||
s = foo(this); | ||
} | ||
|
||
class D { | ||
// Error expected | ||
get x() { | ||
return this.x; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the error message a bit more explicit. I do not find "circularity" particularly helpful, specially that we do not print the cycle. how about:
'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its initializer.
Function implicitly has return type 'any' because it does not have a return type annotation and it is referenced directly or indirectly in at least one if its return expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I will change the error messages.