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

Regression: properties erroneously reported as possibly null #4209

Closed
Cherry opened this issue Apr 4, 2024 · 2 comments
Closed

Regression: properties erroneously reported as possibly null #4209

Cherry opened this issue Apr 4, 2024 · 2 comments
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@Cherry
Copy link

Cherry commented Apr 4, 2024

With the following contrived example.vue file:

<script setup lang="ts">
type Bar = {
	id: string;
} | null;

type Example = {
	foo: {
		bar: Bar;
	};
	doSomething(id: string): void;
};
const example: Example = {
	foo: {
		bar: {
			id: '123',
		},
	},
	doSomething(id: string) {
		console.log(id);
	},
};
</script>
<template>
	<button
		v-if="example.foo.bar"
		type="button"
		v-on:click="example.doSomething(example.foo.bar.id)"
	>
		{{ example.foo.bar.id }}
	</button>
</template>

vue-tsc@2.0.7 reports no errors.
vue-tsc@2.1.0 reports: '__VLS_ctx.example.foo.bar' is possibly 'null'. [Ln 27, Col 35]

Given that this is wrapped in a v-if="example.foo.bar", I wouldn't expect this to ever be null.

@Cherry
Copy link
Author

Cherry commented Apr 4, 2024

Specifically, it seems to be due to the bump of volar. Here's a minimal reproduction:

  • See branch main for working in vue-tsc@2.0.7 and older volar
  • See branch 2.1.0 for erroring in vue-tsc@2.1.0 and newer volar

https://github.com/Cherry/volar-erroneous-null-repro

Run npm run test in each branch to see the issue.

@sid-6581
Copy link

sid-6581 commented Apr 4, 2024

I have the same issue. v-if doesn't narrow the type for events anymore in 2.0.10.

@johnsoncodehk johnsoncodehk added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

3 participants