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

Vue template: Object is possibly 'undefined' errors #1134

Closed
marcianos opened this issue Apr 1, 2022 · 1 comment
Closed

Vue template: Object is possibly 'undefined' errors #1134

marcianos opened this issue Apr 1, 2022 · 1 comment
Labels
question Further information is requested

Comments

@marcianos
Copy link

I try to use Vite + Vue + Typescript with Volar plugin.

Vue version: 3.2.25
Typescript version: 4.5.5
Vite version: 2.8.0
Vue-tsc: 0.33.9

Example link

I generate: const testing: Ref<string | undefined> = ref();.

At beginning this value is undefined and in onBeforeMount() I set this value to a string. In vue template the div should only be generated when testing has a value (v-if="testing"). For the input field the v-model has type string and not string or undefined (which should be right).

The button click event errors with the message:

Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'.

In the example you can see this error message when you run vue-tsc --noEmit.

Is this behavior intended? And how can I solve this issue when I have a ref which is first undefined and then I receive the concrete value from an api call?

@johnsoncodehk
Copy link
Member

This is design behavior, you could use @click="testClick(testing!)", there are some discussion: #146

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

No branches or pull requests

2 participants