vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.42k stars 9.58k forks source link

Changes to typescript overloads in Store instance methods. #2142

Open Surof1n opened 2 years ago

Surof1n commented 2 years ago

Version

3.6.2

Reproduction link

codesandbox.io/s/umtsos

Steps to reproduce

  1. Look up the Union type of the 'path' argument (initModule method)

  2. An error appears about the incompatibility of the types of arguments for the registerModule method, the typing of this method does not support the use of the Union type:string | string[]

  3. Familiarize yourself with the typing of this method by reference and match the union type to the two method declarations: https://github.com/vuejs/vuex/blob/3.x/types/index.d.ts

For more information, use the resource: https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#use-union-types

What is expected?

Support Union type: string | string[] given the already described type overloads of the registerModule method, the following errors will be eliminated when resolving the conflict:

1. Argument of type "string | string[]" is not assignable to parameter of type "string[]".
2. Argument of type "string | string[] is not assignable to parameter of type "string".

What is actually happening?

When comparing the type "string | string[]", an error about type incompatibility is thrown, but given the type overloads, it should be possible to put an argument with the union type.