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

2.7: TS7056 Triggered when ref type argument has a vue component as an option and an initial ref value is passed #12947

Open
nermolov opened this issue Feb 2, 2023 · 2 comments

Comments

@nermolov
Copy link

nermolov commented Feb 2, 2023

Version

2.7.14

Reproduction link

github.com

Steps to reproduce

  • Create a new Vue 2 + Typescript project with npx vue create
  • Upgrade project to Vue 2.7 with npm install vue@2.7.14
  • Set "declaration": true in tsconfig.json
  • Declare a ref in your component setup whose type argument is a union of a different vue component or null, and set its initial value to null: const helloWorld = ref<InstanceType<typeof HelloWorld> | null>(null);
  • Return the ref from setup

What is expected?

No error

What is actually happening?

npx vue-tsc --emitDeclarationOnly
src/App.vue:12:1 - error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

 12 export default defineComponent({
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 13   name: 'App',
    ~~~~~~~~~~~~~~
... 
 23   }
    ~~~
 24 });
    ~~~

Not passing an initial value, e.g.

const helloWorld = ref<InstanceType<typeof HelloWorld> | null>();

does not trigger the error, nor does passing an initial value when the type argument does not include another Vue component, e.g.

const xyz = ref<string | undefined>(undefined);

"declaration": true is needed because the repo this issue was discovered in is a shared package that is imported by other Vue applications, and type declarations are required.

This issue does not happen with Vue 2.6 with @vue/composition-api, only 2.7

@5z5
Copy link

5z5 commented Feb 17, 2023

Maybe it's typescript

@Buyu1016
Copy link

I saw a similar problem in TypeScript, microsoft/TypeScript#43817, may be able to help you.

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