6
6
7
7
/**
8
8
* @typedef {import('../utils').ComponentProp } ComponentProp
9
+ * @typedef {import('../utils').ComponentEmit } ComponentEmit
9
10
* @typedef {import('../utils').GroupName } GroupName
10
11
*/
11
12
@@ -33,10 +34,19 @@ function isComma(node) {
33
34
}
34
35
35
36
/**
36
- * @param { string } nodeType
37
+ * @typedef { Exclude<ComponentProp | ComponentEmit, {type:'infer-type'}> & { node: {type: 'Property' | 'SpreadElement'} } } ValidComponentPropOrEmit
37
38
*/
38
- function isValidProperties ( nodeType ) {
39
- return [ 'Property' , 'SpreadElement' ] . includes ( nodeType )
39
+ /**
40
+ * @template {ComponentProp | ComponentEmit} T
41
+ * @param {T } propOrEmit
42
+ * @returns {propOrEmit is ValidComponentPropOrEmit & T }
43
+ */
44
+ function isValidProperties ( propOrEmit ) {
45
+ return Boolean (
46
+ propOrEmit . type !== 'infer-type' &&
47
+ propOrEmit . node &&
48
+ [ 'Property' , 'SpreadElement' ] . includes ( propOrEmit . node . type )
49
+ )
40
50
}
41
51
42
52
/**
@@ -320,11 +330,9 @@ module.exports = {
320
330
} ) ,
321
331
utils . defineScriptSetupVisitor ( context , {
322
332
onDefinePropsEnter ( _ , props ) {
323
- const propNodes = /** @type {(Property | SpreadElement)[] } */ (
324
- props
325
- . filter ( ( prop ) => prop . node && isValidProperties ( prop . node . type ) )
326
- . map ( ( prop ) => prop . node )
327
- )
333
+ const propNodes = props
334
+ . filter ( isValidProperties )
335
+ . map ( ( prop ) => prop . node )
328
336
329
337
const withinOption = parseOption ( options , OptionKeys . WithinOption )
330
338
const propsOption = withinOption && parseOption ( withinOption , 'props' )
@@ -337,11 +345,9 @@ module.exports = {
337
345
)
338
346
} ,
339
347
onDefineEmitsEnter ( _ , emits ) {
340
- const emitNodes = /** @type {(Property | SpreadElement)[] } */ (
341
- emits
342
- . filter ( ( emit ) => emit . node && isValidProperties ( emit . node . type ) )
343
- . map ( ( emit ) => emit . node )
344
- )
348
+ const emitNodes = emits
349
+ . filter ( isValidProperties )
350
+ . map ( ( emit ) => emit . node )
345
351
346
352
const withinOption = parseOption ( options , OptionKeys . WithinOption )
347
353
const emitsOption = withinOption && parseOption ( withinOption , 'emits' )
0 commit comments