question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type not preserved with array ref since 3.2.30

See original GitHub issue

Version

3.2.30

Reproduction link

sfc.vuejs.org/

Steps to reproduce

In the following block of Typescript code, look at the type of the list variable.

import { ref } from "vue";
type DropdownOption = { value: string; name: string };
const list = ref<DropdownOption[]>([]);

What is expected?

The return type of ref<DropdownOption[]>([]) to be Ref<DropdownOption[]>.

What is actually happening?

The return type of ref<DropdownOption[]>([]) is currently Ref<{value: string, name: string}[]>.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
CipherdevNLcommented, Feb 9, 2022

In a project I’m working on the same issue occurred during an upgrade of only the yarn.lock file. Did some research and apparently if the version of @vue/reactivity mismatches with the pinned version of vue in the package.json it will produce this issue.

For the typescript type checking we’re using vue-tsc and it seems like they have an indirect dependency on @vue/reactivity@3.2.27, thus making it possible for a mismatch upgrade in the yarn.lock file.

After bumping vue in the package.json to the same version it resolves the issue. So it seems like typescript get confused somehow when @vue/reactivity is not matching the version of other core vue packages.

Don’t know if an investigation is really needed to know why a mismatch in versions result in this error, because it’s supposed the version of core vue packages must be the same. But it might worth looking into if it’s allowed that vue-tsc can result in such mismatch of core packages in the yarn.lock. Especially when vue-tsc is named on the vue site.

1reaction
JoostKersjescommented, Feb 7, 2022

I could be off-base here, but I think the problem statement above is the issue related to this Typescript error.

error TS2322: Type 'HTMLLIElement' is not assignable to type '{ type: string; value: number; addEventListener: { <K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLLIElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | ... 1 more ... | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... ...'.
  Types of property 'offsetParent' are incompatible.

That error does not appear in vue<=3.2.29. This is the code producing the error:

const optionElementRefs = ref<HTMLLIElement[]>([]);

// ...

const setOptionElementRef = (element: HTMLLIElement, index: number) => {
  optionElementRefs.value[index] = element;
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference to Array vs reference to array pointer - Stack Overflow
One problem is that your char array is NOT NECESSARILY going to be null-terminated. Since array is an automatic variable that is allocated ......
Read more >
API Reference :: NVIDIA Deep Learning cuDNN Documentation
cudnnMathType_t is an enumerated type used to indicate if the use of Tensor Core operations is permitted in a given library routine. Values....
Read more >
Chapter 10. Arrays
A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object...
Read more >
node-oracledb 5.5.0 Documentation for the Oracle Database ...
Oracle Database driver for Node.js maintained by Oracle Corp. ... WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Read more >
Why is an array a reference type? - Quora
An array is referred to as a reference data type since it specifies a reference to an ... the object is not explicitly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found