deno icon indicating copy to clipboard operation
deno copied to clipboard

`Iterator` proposal type declarations are missing

Open ben-laird opened this issue 10 months ago • 3 comments

Version: Deno 1.42.3

Explanation

Hello! I'm using Deno in experiments with TypeScript to learn more about the language, especially surrounding iterators and bleeding-edge ECMAScript proposals. As of 1.42 I had read that Deno has support for the Temporal API as well as the new Iterator API. When I went to use them in my own code, the language server didn't even recognize the Iterator namespace, and running any code with the Temporal namespace with Deno throws a ReferenceError. Here is a link to a minimal reproduction of the issue.

Reproduction

  1. Clone the main branch of this repository
  2. Run deno test at the root of the project
  3. Observe thrown errors:
  • TS2693 [ERROR]: 'Iterator' only refers to a type, but is being used as a value here.
  • When the offending code of the previous error is commented out, error: ReferenceError: Temporal is not defined

Details

Output of deno --version:

deno 1.42.3 (release, aarch64-apple-darwin)
v8 12.3.219.9
typescript 5.4.3

ben-laird avatar Apr 13 '24 18:04 ben-laird

Temporal is still an unstable API, to use it you need to run Deno with --unstable-temporal command line option. (seems like it's missing from the manual: https://docs.deno.com/runtime/manual/tools/unstable_flags )

Not sure about Iterator

jtoppine avatar Apr 13 '24 21:04 jtoppine

Thanks for the fix with Temporal, wish the error was a bit more helpful.

ben-laird avatar Apr 14 '24 01:04 ben-laird

Upstream: https://github.com/microsoft/TypeScript/pull/58222

petamoriken avatar May 26 '24 21:05 petamoriken

I get a lot of type errors like Property 'map' does not exist on type 'IterableIterator<x>' . Is that the same issue?

Is it likely to be resolved soon, now that https://github.com/microsoft/TypeScript/pull/58222 is merged?

adamgreg avatar Sep 12 '24 16:09 adamgreg

TypeScript 5.6 supports Stage 3 Iterator Helpers types, so just wait for it to be imported to Deno. That will probably take at least a few months, as TypeScript code needs to be bundled and patched.

petamoriken avatar Sep 12 '24 17:09 petamoriken

I get a lot of type errors like Property 'map' does not exist on type 'IterableIterator' . Is that the same issue?

Yes, an IteratorObject<T, TReturn = unknown, TNext = unknown> interface is introduced and a map method is defined for it.

petamoriken avatar Sep 12 '24 18:09 petamoriken

OK, that's great news thanks!

adamgreg avatar Sep 12 '24 19:09 adamgreg