Skip to content

Generator's return "any" type when yielded  #10148

Closed
@rylev

Description

@rylev

TypeScript Version: 1.8, 2.0, and nightly

Code
The following code compiles even though it would appear that result should have type string:

function* myGenerator() {
  yield "hello"
}

function* myOtherGenerator() {
  const result = yield myGenerator()
  result.methodNotAvailableOnString()
}

Expected behavior:
When a generator is yielded I expected that the type of the subsequent variable to be whatever T is in myGenerator's return type IterableIterator<T>

Actual behavior:
This is however not the case. result has type any. Should the TypeScript compiler be able to infer that that type of result should be string?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions