Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Allow specifying non-iterable return types for generators #854

Open
Tracked by #1074
kdy1 opened this issue Mar 24, 2023 · 0 comments
Open
Tracked by #1074

Allow specifying non-iterable return types for generators #854

kdy1 opened this issue Mar 24, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@kdy1
Copy link
Member

kdy1 commented Mar 24, 2023

We should allow code like

async function * explicitReturnType16(): {} {
yield 1;
}

Currently, stc fails with

  x SimpleAssignFailed {
  |     span: Span {
  |         lo: BytePos(
  |             3722,
  |         ),
  |         hi: BytePos(
  |             3729,
  |         ),
  |         ctxt: #0,
  |     },
  |     cause: Some(
  |         context: tried to get an element type from an async iterator for normal yield (at crates/stc_ts_file_analyzer/src/analyzer/stmt/return_type.rs:516:26)
  |         context: tried to get element of iterator as a fallback logic for async iterator (at crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs:505:14)
  |         context: tried to get a type of an iterator to get the element type of it () (at crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs:785:14)
  |         context: tried to get iterator (at crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs:595:64)
  |         context: tried to convert a type ({
  |         };) to an iterator (at crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs:760:13)
  |         context: tried to call `[Symbol.iterator]()` (at crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs:757:14)
  |         context: tried to call a property of an object ({
  |         };) (at crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs:969:10)
  |         context: failed to call property of type elements (at crates/stc_ts_file_analyzer/src/analyzer/expr/call_new.rs:1290:10)
  |         MustHaveSymbolAsyncIteratorThatReturnsIterator {
  |             span: Span {
  |                 lo: BytePos(
  |                     3722,
  |                 ),
  |                 hi: BytePos(
  |                     3729,
  |                 ),
  |                 ctxt: #0,
  |             },
  |         },
  |     ),
  | }
     ,-[$DIR/tests/conformance/types/asyncGenerators/types.asyncGenerators.es2018.1.ts:118:1]
 118 | async function * explicitReturnType16(): {} {
 119 |     yield 1;
     :     ^^^^^^^
 120 | }
     `----

But we should not report such errors if the return type is not iterable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Development

No branches or pull requests

1 participant