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

v1.8.10 Generics: defineComponent missing type overload definition when importing a script setup generic component #3257

Closed
Chuuone opened this issue Jun 7, 2023 · 11 comments · Fixed by #3569
Labels
bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@Chuuone
Copy link

Chuuone commented Jun 7, 2023

Importing a child component defined using <script setup lang="ts" generic="T extends Record">
into a component defined using <script lang="ts"> and defineComponent() will cause typing issue specified below.

Example breakdown
Define a child component
// TableComponent.vue

<script setup lang="ts" generic="TRow extends DataType = DataType">

Create a parent component defined using
MainComponent.vue

<script lang="ts">
import TableComponent from "TableComponent.vue";

defineComponent({components: {TableComponent});
</script>

The typing issue
Screenshot 2023-06-07 095116

@Chuuone
Copy link
Author

Chuuone commented Jun 14, 2023

#2709 Reoccurrance of this problem

@Chuuone Chuuone changed the title Generics: defineComponent missing type overload definition when importing component with syntax <script lang="ts" setup generic="T extends DataType = DataType"> v.1.8.5 Generics: defineComponent missing type overload definition when importing component with syntax <script lang="ts" setup generic="T extends DataType = DataType"> Jul 20, 2023
@Chuuone Chuuone changed the title v.1.8.5 Generics: defineComponent missing type overload definition when importing component with syntax <script lang="ts" setup generic="T extends DataType = DataType"> v1.8.5 Generics: defineComponent missing type overload definition when importing component with syntax <script lang="ts" setup generic="T extends DataType = DataType"> Jul 20, 2023
@Chuuone Chuuone changed the title v1.8.5 Generics: defineComponent missing type overload definition when importing component with syntax <script lang="ts" setup generic="T extends DataType = DataType"> v1.8.5 Generics: defineComponent missing type overload definition when importing a script setup generic component Jul 20, 2023
@Chuuone Chuuone changed the title v1.8.5 Generics: defineComponent missing type overload definition when importing a script setup generic component v1.8.10 Generics: defineComponent missing type overload definition when importing a script setup generic component Sep 7, 2023
@so1ve so1ve added bug Something isn't working pending triage and removed bug Something isn't working labels Sep 18, 2023
@so1ve
Copy link
Member

so1ve commented Sep 18, 2023

Not sure why, but I can't reproduce it now.

@Chuuone
Copy link
Author

Chuuone commented Sep 18, 2023

Not sure why, but I can't reproduce it now.

I just tried it in v.1.8.11 in case it was fixed there. Unfortunately isn't.

Are you reproducing in stackblitz or vscode? I've found the issue is not reproducible in stackblitz.

@so1ve
Copy link
Member

so1ve commented Sep 18, 2023

In vscode. This is my reproduction: https://github.com/so1ve/language-tools/tree/fix/issue-3257. Am I doing something wrong? Maybe related to your vue / typescript version?

@Chuuone
Copy link
Author

Chuuone commented Sep 18, 2023

Your parent component seems to have a script setup <script setup lang="ts"> and export defineComponent() all in one. In my example we just use defineComponent on parent and setup generic in child. :)

Is using both valid or a mistake?

@so1ve
Copy link
Member

so1ve commented Sep 18, 2023


:(

I didn't export the component inside script setup; I just called defineComponent to check if the type works.

@Chuuone
Copy link
Author

Chuuone commented Sep 18, 2023

Alright, that is odd. Well i am using ts 5.2.2 and Volar 1.8.11. I think i need to try to fork your test and see if it behaves then in case something in my project is throwing things off.

Out of curiosity, are shims defined in your test?

declare module "*.vue" {
	import type {DefineComponent} from "vue";

	const component: DefineComponent<{}, {}, any>;

	export default component;
  }

@so1ve
Copy link
Member

so1ve commented Sep 18, 2023

No :D You don't need this if you enable take over mode.

@Chuuone
Copy link
Author

Chuuone commented Sep 18, 2023

Think i need some help with the fork. I forked the project, checked out your branch fix/issue-3257

Ran npm i
npm i

The problem is, there is no type hinting going on whatsoever. Note how i am using a Comp thats not defined, and things do not hint.

Screenshot 2023-09-18 083023

Update

Figured it out how to setup the fork; had to install some extra things.

The type hinting is working here for me too. Going to look into this more.

@Chuuone
Copy link
Author

Chuuone commented Sep 18, 2023

I think i figured it out. The error happens due to the new emits syntax introduced in 3.3+

Here is a minimal reproduction.

Comp.d.ts

<script setup lang="ts" generic="TRow extends DataType = DataType">
import type {DataType} from "./Comp";

/* Taken from https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits */
export type Emits = {
  change: [id: number] // named tuple syntax
  update: [value: string]
};

defineEmits<Emits>();
</script>

@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed pending triage labels Sep 18, 2023
@so1ve
Copy link
Member

so1ve commented Sep 18, 2023

Thanks @Chuuone, this reproduction works 👍

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

Successfully merging a pull request may close this issue.

2 participants