Subscribe on changes!

UnwrapRefSimple where T extends Array discards symbol keys

avatar
May 20th 2021

Version

3.1.0-beta.3

Reproduction link

https://codesandbox.io/s/white-architecture-7frqz?file=/src/main.ts

Steps to reproduce

  • Fork repository

  • See type of state.myExtendedArray inferred by editor & type error "... must have a '[Symbol.iterator]()' method that returns an iterator."

What is expected?

The type of state.myExtendedArray should be ExtendedArray<number> or some variation which includes the Symbol.iterator key as the underlying array type does.

What is actually happening?

Symbol properties are not being extracted


This issue seems to have been intruduced in https://github.com/vuejs/vue-next/commit/82b28a5ecb95be1565e50427bfd5eefe4b2d408c, where a separate case for T extends Array<any> which doesn't use SymbolExtract<T> like UnwrappedObject<T> does was added to the type returned by UnwrapRefSimple<T>. My issues seem to be resolved if I append & SymbolExtract<T> to https://github.com/vuejs/vue-next/blob/82b28a5ecb95be1565e50427bfd5eefe4b2d408c/packages/reactivity/src/ref.ts#L171