Bug in typing iterable iterator with symbol

未關閉
#32,408 3 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
typescript
領域
compilers

研究方向

在連結的 Playground 中重現 index.ts 中的範例,並確認針對 IterableIterator 回報的可指派性錯誤。追蹤可迭代迭代器型別如何處理 number | symbol 聯集,然後驗證該範例不會出現 TS2322 錯誤即可通過型別檢查。

由索引模型根據 Issue 內容生成。

描述

Bug Domain: Literal Types

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

主要語言
Go
星號
111k
分支
14.4k
平均合併
1 天 19 小時
30 天內合併 PR
117

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。