Skip to content

Bug in typing iterable iterator with symbol #32408

Open

Description

TypeScript Version: 3.6.0-dev.20190713

Search Terms: symbol iterableiterator

Code

const Foo = Symbol()
type FooType = typeof Foo

type SomeType = number | FooType

function giveMeSomeType(): SomeType {
    return (Math.random() > 0.5) ? 42 : Foo
}

const it: IterableIterator<SomeType> = [giveMeSomeType()][Symbol.iterator]()

Expected behavior: local constant it is typechecked correctly

Actual behavior:

Typechecking fails with error:

index.ts:10:7 - error TS2322: Type 'IterableIterator<number | symbol>' is not assignable to type 'IterableIterator<SomeType>'.
  Type 'number | symbol' is not assignable to type 'SomeType'.
    Type 'symbol' is not assignable to type 'SomeType'.

10 const it: IterableIterator<SomeType> = [giveMeSomeType()][Symbol.iterator]()

Playground Link: http://www.typescriptlang.org/play/#code/MYewdgzgLgBAYiEMC8MDKBPAtgIxAGwAoBKAKCgwAcBTeRAFSttQppADM6RTyn0Qs1RjRQwwAV1zUATjAA+XYdR4B6FTA4xQ46RFoBDCBEm0oAC32xzASwgx24sMCjXwWkOPwATGNOpQdMBhqa3MZLg1ZCSlpUgcnFzcAc2sAN2oAWWo0ASEmEgAufkElGABvUhgq339AmAAWACZSAF8eUEhYUKKASSgZfRx8aj6BqBBpAB4ckqYAPlEAbRT0rJm8mhIAXUXMXAIAOlCxia2SUiA

Related Issues: couldn't find

Activity

  1. added
    Needs Investigation
    on Jul 31, 2019
  2. added
    Rescheduled
    on Aug 31, 2020
  3. 13 remaining items

  4. removed
    Rescheduled
    on Feb 4, 2022
  5. added 3 commits that reference this issue on Feb 10, 2022
  6. added
    Domain: Literal Types
    on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: Literal Types

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions