Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type conflict, how to increase weight #397

Open
5 tasks done
jiangmaniu opened this issue Aug 2, 2022 · 2 comments
Open
5 tasks done

Type conflict, how to increase weight #397

jiangmaniu opened this issue Aug 2, 2022 · 2 comments

Comments

@jiangmaniu
Copy link

Describe the bug

After I download the template, I execute the ni command to install the relevant dependencies of the template After installation, add the following code to <script> of App.vue

<script setup lang="ts">
// Mock ref variables returned from hooks utility functions
const refDataA = ref(1)
const refDataB = ref(2)
setInterval(() => { refDataA.value++; refDataB.value *= 2 }, 1000)

// use in business
const $refDataA = $(refDataA)
const $refDataB = $(refDataB)

// Simulate the `use` tool function like hooks
function useAdd(...params: Ref<number>[]) {
  return computed(() => params.reduce((acc, param) => { return acc + param.value }, 0))
}

// Need to `use xxx as unknown as number` assertion
// Otherwise it will be treated as JQuery<Ref<number>> type
const afterComputed = useAdd($$($refDataA as unknown as number), $$($refDataB as unknown as number))

// continuous output
watch(afterComputed, () => console.log(afterComputed.value))
</script>

When using $() to convert Ref to reactive variables, the type of $() is overwritten by the type of jquery in cypress

image

image

image

I was looking at tsconfig.ts and found that the type of cypress package was excluded and only included in tsconfig.ts inside the /cypress folder, but this doesn't seem to work, in vue vscode in the file still recognizes the type of cypress package, I don't know what's going on here.

I tried uninstalling the cypress package to test if the conflict was really caused by the cypress package, which turned out to be correct.

image

While the solution works, I need to use the cypress package in my project to test my project, so I can't live without it.

I try to use xxx as unknown as number to assert the transformed variable before using it, it works, but if I need to assert every time I use it, it will increase the burden on my coding mind, I am eager Solve the conflict problem once and for all from a global perspective.

What should I do please?

Reproduction

https://github.com/jiangmaniu/vitesse-type-conflict-repo

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600K      
    Memory: 16.64 GB / 31.78 GB
  Binaries:
    Node: 16.15.1 - D:\Program Files\nodejs\node.EXE        
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.11.0 - D:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.423.0), Chromium (103.0.1264.77)
    Internet Explorer: 11.0.19041.1

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@kylegl
Copy link

kylegl commented Oct 21, 2022

Did you ever solve this? I am getting the same issue.

@NamesMT
Copy link

NamesMT commented Dec 11, 2022

+1, another workaround is adding import { $ } from 'vue/macros' everywhere you need it, that corrects the typing but kinda defeats the whole auto-import feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants