microsoft / microsoft/TypeScript
Bug in typing iterable iterator with symbol
Open
Nobody has claimed this yet.
Bug
Domain: Literal Types
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example from index.ts in the linked Playground and confirm the reported assignability error for IterableIterator. Trace how iterable iterator types handle the number | symbol union, then verify that the example typechecks without the TS2322 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100