Skip to content

Commit

Permalink
fix(language-core): nullable modelvalues (#4648)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmatter authored Aug 9, 2024
1 parent 35474d2 commit eef948d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function* generateDefinePropType(scriptSetup: NonNullable<Sfc['scriptSetup']>, p
}
else if ((defineProp.name && defineProp.nameIsString) || !defineProp.nameIsString) {
// Infer from actual prop declaration code
yield `NonNullable<typeof ${propName}['value']>`;
yield `typeof ${propName}['value']`;
}
else if (defineProp.defaultValue) {
// Infer from defineProp({default: T})
Expand Down
1 change: 1 addition & 0 deletions test-workspace/tsc/vue2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"../vue3/#4327",
"../vue3/#4512",
"../vue3/#4540",
"../vue3/#4646",
"../vue3/components",
"../vue3/defineEmits",
"../vue3/defineModel",
Expand Down
13 changes: 13 additions & 0 deletions test-workspace/tsc/vue3/#4646/child.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>{{ msg }}</template>

<script lang="ts" setup>
import {exactType} from 'tsc/shared'
import {PropType} from 'vue'
const msg = defineModel('msg', {
type: String as PropType<string | null>,
required: true,
})
exactType(msg.value, {} as string | null)
</script>
5 changes: 5 additions & 0 deletions test-workspace/tsc/vue3/#4646/child2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>{{ other }}</template>

<script lang="ts" setup>
const other = defineModel<string | null>('other')
</script>
15 changes: 15 additions & 0 deletions test-workspace/tsc/vue3/#4646/parent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<child v-model:msg="msg" />
<child :msg="msg" @update:msg="v => exactType(v, {} as string|null)" />

<child2 v-model:other="other" />
</template>
<script lang="ts" setup>
import { exactType } from 'tsc/shared'
import { ref } from 'vue'
import child from './child.vue'
import child2 from './child2.vue'
const msg = ref<string | null>('test')
const other = ref<string | null>('test2')
</script>

0 comments on commit eef948d

Please sign in to comment.