forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check return types of generator functions.
Fixes microsoft#18726
- Loading branch information
1 parent
0abfd6a
commit 2f0415a
Showing
16 changed files
with
354 additions
and
21 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
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
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,27 @@ | ||
tests/cases/compiler/iteratorReturn.ts(15,11): error TS2322: Type '"str"' is not assignable to type 'number'. | ||
tests/cases/compiler/iteratorReturn.ts(16,5): error TS2322: Type '1' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/iteratorReturn.ts (2 errors) ==== | ||
interface Coroutine extends Iterator<number> { | ||
return?(effect?: string): IteratorResult<string>; | ||
} | ||
|
||
interface Process extends Coroutine { | ||
[Symbol.iterator](): Coroutine; | ||
} | ||
|
||
let good = function*(): Process { | ||
yield 1; | ||
return "str"; | ||
}; | ||
|
||
let bad = function*(): Process { | ||
yield "str"; | ||
~~~~~ | ||
!!! error TS2322: Type '"str"' is not assignable to type 'number'. | ||
return 1; | ||
~~~~~~~~~ | ||
!!! error TS2322: Type '1' is not assignable to type '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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [iteratorReturn.ts] | ||
interface Coroutine extends Iterator<number> { | ||
return?(effect?: string): IteratorResult<string>; | ||
} | ||
|
||
interface Process extends Coroutine { | ||
[Symbol.iterator](): Coroutine; | ||
} | ||
|
||
let good = function*(): Process { | ||
yield 1; | ||
return "str"; | ||
}; | ||
|
||
let bad = function*(): Process { | ||
yield "str"; | ||
return 1; | ||
}; | ||
|
||
|
||
//// [iteratorReturn.js] | ||
let good = function* () { | ||
yield 1; | ||
return "str"; | ||
}; | ||
let bad = function* () { | ||
yield "str"; | ||
return 1; | ||
}; |
Oops, something went wrong.