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.
built-in iterators should be disposable (microsoft#59633)
- Loading branch information
Showing
22 changed files
with
950 additions
and
104 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
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.errors.txt
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,19 @@ | ||
awaitUsingDeclarationsWithAsyncIteratorObject.ts(11,23): error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
|
||
|
||
==== awaitUsingDeclarationsWithAsyncIteratorObject.ts (1 errors) ==== | ||
declare const ai: AsyncIterator<string, undefined>; | ||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
declare const ag: AsyncGenerator<string, void>; | ||
|
||
async function f() { | ||
// should pass | ||
await using it0 = aio; | ||
await using it1 = ag; | ||
|
||
// should fail | ||
await using it2 = ai; | ||
~~ | ||
!!! error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.symbols
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,33 @@ | ||
//// [tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsWithAsyncIteratorObject.ts] //// | ||
|
||
=== awaitUsingDeclarationsWithAsyncIteratorObject.ts === | ||
declare const ai: AsyncIterator<string, undefined>; | ||
>ai : Symbol(ai, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 0, 13)) | ||
>AsyncIterator : Symbol(AsyncIterator, Decl(lib.es2018.asynciterable.d.ts, --, --)) | ||
|
||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
>aio : Symbol(aio, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 1, 13)) | ||
>AsyncIteratorObject : Symbol(AsyncIteratorObject, Decl(lib.es2018.asynciterable.d.ts, --, --), Decl(lib.esnext.disposable.d.ts, --, --)) | ||
|
||
declare const ag: AsyncGenerator<string, void>; | ||
>ag : Symbol(ag, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 13)) | ||
>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) | ||
|
||
async function f() { | ||
>f : Symbol(f, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 47)) | ||
|
||
// should pass | ||
await using it0 = aio; | ||
>it0 : Symbol(it0, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 6, 15)) | ||
>aio : Symbol(aio, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 1, 13)) | ||
|
||
await using it1 = ag; | ||
>it1 : Symbol(it1, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 7, 15)) | ||
>ag : Symbol(ag, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 2, 13)) | ||
|
||
// should fail | ||
await using it2 = ai; | ||
>it2 : Symbol(it2, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 10, 15)) | ||
>ai : Symbol(ai, Decl(awaitUsingDeclarationsWithAsyncIteratorObject.ts, 0, 13)) | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/awaitUsingDeclarationsWithAsyncIteratorObject.types
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/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsWithAsyncIteratorObject.ts] //// | ||
|
||
=== awaitUsingDeclarationsWithAsyncIteratorObject.ts === | ||
declare const ai: AsyncIterator<string, undefined>; | ||
>ai : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const aio: AsyncIteratorObject<string, undefined, unknown>; | ||
>aio : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
declare const ag: AsyncGenerator<string, void>; | ||
>ag : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
async function f() { | ||
>f : () => Promise<void> | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
|
||
// should pass | ||
await using it0 = aio; | ||
>it0 : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>aio : AsyncIteratorObject<string, undefined, unknown> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
await using it1 = ag; | ||
>it1 : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>ag : AsyncGenerator<string, void, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
// should fail | ||
await using it2 = ai; | ||
>it2 : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>ai : AsyncIterator<string, undefined, any> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/awaitUsingDeclarationsWithIteratorObject.errors.txt
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,28 @@ | ||
awaitUsingDeclarationsWithIteratorObject.ts(20,23): error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
|
||
|
||
==== awaitUsingDeclarationsWithIteratorObject.ts (1 errors) ==== | ||
declare const i: Iterator<string, undefined>; | ||
declare const io: IteratorObject<string, undefined, unknown>; | ||
declare const g: Generator<string, void>; | ||
|
||
class MyIterator extends Iterator<string> { | ||
next() { return { done: true, value: undefined }; } | ||
} | ||
|
||
async function f() { | ||
// should pass | ||
await using it0 = io; | ||
await using it1 = g; | ||
await using it2 = Iterator.from(i) | ||
await using it3 = new MyIterator(); | ||
await using it4 = [].values(); | ||
await using it5 = new Map<string, string>().entries(); | ||
await using it6 = new Set<string>().keys(); | ||
|
||
// should fail | ||
await using it7 = i; | ||
~ | ||
!!! error TS2851: The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'. | ||
} | ||
|
Oops, something went wrong.