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

defineCustomElement props become readonly when component defines array emits #11353

Closed
andylizi opened this issue Jul 14, 2024 · 1 comment · Fixed by #11384
Closed

defineCustomElement props become readonly when component defines array emits #11353

andylizi opened this issue Jul 14, 2024 · 1 comment · Fixed by #11384

Comments

@andylizi
Copy link
Contributor

andylizi commented Jul 14, 2024

Vue version

3.4.31

Link to minimal reproduction

https://stackblitz.com/edit/vue-ce-type-repro?file=src%2Fmain.ts

Steps to reproduce

Using the reproduction link:

  1. Open the reproduction link and wait for npm install to finish.
  2. Run npx vue-tsc
  3. Observe type error.
  4. Comment out the defineEmits line in counter.ce.vue, run vue-tsc again.
  5. Observe that the type error disappears.

Manual setup:

const Comp1Vue = defineComponent({
  props: {
    a: Number,
  },
  emits: ['click'],
})
const Comp = defineCustomElement(Comp1Vue)

new Comp().a = 42   // property 'a' is read-only

What is expected?

No type error as props shouldn't be read-only.

What is actually happening?

src/main.ts:13:4 - error TS2540: Cannot assign to 'count' because it is a read-only property.

   el.count = 42;

This error only appears if defineEmits is present. It shows up in both vscode and vue-tsc.

System Info

No response

Any additional comments?

This is a variant of #7782, which was fixed by #7937 but only for object-style emit declarations. However, type-only emit declarations in SFCs are always compiled into arrays.

@andylizi andylizi changed the title defineCustomElement makes props readonly when used with defineEmits defineCustomElement props become readonly when component defines array emits Jul 17, 2024
yyx990803 pushed a commit that referenced this issue Aug 5, 2024
@yyx990803
Copy link
Member

closed via #11384

@github-actions github-actions bot locked and limited conversation to collaborators Aug 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants