Skip to content

Bug in typing iterable iterator with symbol #32408

Open
@swistak35

Description

@swistak35

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions