Skip to content

fix(language-core): make model modifiers optional #4978

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

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

stafyniaksacha
Copy link
Collaborator

@stafyniaksacha stafyniaksacha commented Nov 3, 2024

This pull request includes changes to improve the handling of component property modifiers in the generateComponentProps function and its associated tests.

It aims to better reflect modelModifiers type marking keys as optional:

<!-- MyComp.vue -->
<script setup lang="ts">
const [modelValue, modelModifiers] = defineModel<string, 'foo' | 'bar'>()

// modelModifiers.foo?: true
// modelModifiers.bar?: true
</script>

With this update, we can omit keys when manually defining model-modifiers prop

<template>
  <!-- Type '{ foo: true; }' is missing the following properties from type 'Record<"foo" | "bar", true>': bar -->
  <MyComp :model-modifiers="{ foo: true }" />
</template>

Note that it will also fix type when using vitest and @vue/test-utils:

import { MyComp } from './MyComp.vue'
import { mount } from '@vue/test-utils'
import { it } from 'vitest'

it('should foo modifier', async () => {
  const component = mount(MyComp, {
    props: {
	  // Type '{ foo: true; }' is missing the following properties from type 'Record<"foo" | "bar", true>': bar
      'modelModifiers': { foo: true },
    },
  })
})

Copy link

pkg-pr-new bot commented Nov 3, 2024

Open in Stackblitz

vue-component-meta

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-meta@4978

vue-component-type-helpers

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-component-type-helpers@4978

@vue/language-plugin-pug

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-plugin-pug@4978

@vue/language-core

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-core@4978

@vue/language-server

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-server@4978

@vue/language-service

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/language-service@4978

vue-tsc

pnpm add https://pkg.pr.new/vuejs/language-tools/vue-tsc@4978

@vue/typescript-plugin

pnpm add https://pkg.pr.new/vuejs/language-tools/@vue/typescript-plugin@4978

commit: debf21b

@KazariEX
Copy link
Member

KazariEX commented Nov 3, 2024

Could you please add a test case?

@stafyniaksacha
Copy link
Collaborator Author

Could you please add a test case?

Yes sure, where should I put them ? I only contributed to components-meta env (time ago #4175)

@KazariEX
Copy link
Member

KazariEX commented Nov 3, 2024

Added.

@KazariEX KazariEX enabled auto-merge (squash) November 3, 2024 17:53
@KazariEX KazariEX changed the title fix(language-core): make modelModifiers record as partial fix(language-core): make model modifiers optional Nov 3, 2024
@KazariEX KazariEX merged commit 00f6df5 into vuejs:master Nov 4, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

3 participants