Skip to content

Commit 3170af1

Browse files
committed
fix: ignore generic attribute when generating script import
close vuejs/core#8270
1 parent ffe74e5 commit 3170af1

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

packages/plugin-vue/src/main.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,16 @@ async function linkSrcToDescriptor(
486486

487487
// these are built-in query parameters so should be ignored
488488
// if the user happen to add them as attrs
489-
const ignoreList = ['id', 'index', 'src', 'type', 'lang', 'module', 'scoped']
489+
const ignoreList = [
490+
'id',
491+
'index',
492+
'src',
493+
'type',
494+
'lang',
495+
'module',
496+
'scoped',
497+
'generic',
498+
]
490499

491500
function attrsToQuery(
492501
attrs: SFCBlock['attrs'],

playground/vue/Main.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
<SetupImportTemplate />
2828
<WorkerTest />
2929
<Url />
30+
<TsGeneric msg="hello" />
3031
</template>
3132

3233
<script setup lang="ts">
33-
import { version } from 'vue'
34+
import { version, defineAsyncComponent } from 'vue'
3435
import Hmr from './Hmr.vue'
3536
import HmrTsx from './HmrTsx.vue'
3637
import Syntax from './Syntax.vue'
@@ -50,6 +51,8 @@ import { ref } from 'vue'
5051
import Url from './Url.vue'
5152
import TypeProps from './TypeProps.vue'
5253
54+
const TsGeneric = defineAsyncComponent(() => import('./TsGeneric.vue'))
55+
5356
const time = ref('loading...')
5457
5558
window.addEventListener('load', () => {

playground/vue/TsGeneric.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts" generic="T extends string">
2+
defineProps<{ msg: T }>()
3+
</script>
4+
5+
<template>
6+
<h2>TS with Generics</h2>
7+
<div class="generic">{{ msg }}</div>
8+
</template>

playground/vue/__tests__/vue.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,7 @@ describe('macro imported types', () => {
323323
)
324324
})
325325
})
326+
327+
test('TS with generics', async () => {
328+
expect(await page.textContent('.generic')).toMatch('hello')
329+
})

0 commit comments

Comments
 (0)