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]()
Related Issues: couldn't find