-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report implicit any error for 'yield' result with no contextual type
- Loading branch information
Showing
13 changed files
with
490 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,40 @@ | ||
tests/cases/conformance/generators/generatorImplicitAny.ts(8,19): error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. | ||
tests/cases/conformance/generators/generatorImplicitAny.ts(26,7): error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. | ||
|
||
|
||
==== tests/cases/conformance/generators/generatorImplicitAny.ts (2 errors) ==== | ||
function* g() {} | ||
|
||
// https://github.com/microsoft/TypeScript/issues/35105 | ||
declare function noop(): void; | ||
declare function f<T>(value: T): void; | ||
|
||
function* g2() { | ||
const value = yield; // error: implicit any | ||
~~~~~ | ||
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. | ||
} | ||
|
||
function* g3() { | ||
const value: string = yield; // ok, contextually typed by `value`. | ||
} | ||
|
||
function* g4() { | ||
yield; // ok, result is unused | ||
yield, noop(); // ok, result is unused | ||
noop(), yield, noop(); // ok, result is unused | ||
(yield); // ok, result is unused | ||
(yield, noop()), noop(); // ok, result is unused | ||
for(yield; false; yield); // ok, results are unused | ||
void (yield); // ok, results are unused | ||
} | ||
|
||
function* g5() { | ||
f(yield); // error: implicit any | ||
~~~~~ | ||
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation. | ||
} | ||
|
||
function* g6() { | ||
f<string>(yield); // ok, contextually typed by f<string> | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,57 @@ | ||
//// [generatorImplicitAny.ts] | ||
function* g() {} | ||
function* g() {} | ||
|
||
// https://github.com/microsoft/TypeScript/issues/35105 | ||
declare function noop(): void; | ||
declare function f<T>(value: T): void; | ||
|
||
function* g2() { | ||
const value = yield; // error: implicit any | ||
} | ||
|
||
function* g3() { | ||
const value: string = yield; // ok, contextually typed by `value`. | ||
} | ||
|
||
function* g4() { | ||
yield; // ok, result is unused | ||
yield, noop(); // ok, result is unused | ||
noop(), yield, noop(); // ok, result is unused | ||
(yield); // ok, result is unused | ||
(yield, noop()), noop(); // ok, result is unused | ||
for(yield; false; yield); // ok, results are unused | ||
void (yield); // ok, results are unused | ||
} | ||
|
||
function* g5() { | ||
f(yield); // error: implicit any | ||
} | ||
|
||
function* g6() { | ||
f<string>(yield); // ok, contextually typed by f<string> | ||
} | ||
|
||
//// [generatorImplicitAny.js] | ||
function* g() { } | ||
function* g2() { | ||
const value = yield; // error: implicit any | ||
} | ||
function* g3() { | ||
const value = yield; // ok, contextually typed by `value`. | ||
} | ||
function* g4() { | ||
yield; // ok, result is unused | ||
yield, noop(); // ok, result is unused | ||
noop(), yield, noop(); // ok, result is unused | ||
(yield); // ok, result is unused | ||
(yield, noop()), noop(); // ok, result is unused | ||
for (yield; false; yield) | ||
; // ok, results are unused | ||
void (yield); // ok, results are unused | ||
} | ||
function* g5() { | ||
f(yield); // error: implicit any | ||
} | ||
function* g6() { | ||
f(yield); // ok, contextually typed by f<string> | ||
} |
This file contains 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 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
Oops, something went wrong.