Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/rules/require-valid-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ function getPropertyNode(obj, name) {
}

/**
* @param {Expression} node
* @param {Expression} targetNode
* @returns {string[]}
*/
function getTypes(node) {
function getTypes(targetNode) {
const node = utils.skipTSAsExpression(targetNode)
if (node.type === 'Identifier') {
return [node.name]
} else if (node.type === 'ArrayExpression') {
Expand Down
90 changes: 90 additions & 0 deletions tests/lib/rules/require-valid-default-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,51 @@ ruleTester.run('require-valid-default-prop', rule, {
}
}`,
parserOptions
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Array as PropType<string[]>,
default: () => []
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Object as PropType<{ [key: number]: number }>,
default: () => {}
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Function as PropType<() => number>,
default: () => 10
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
}
],

Expand Down Expand Up @@ -781,6 +826,51 @@ ruleTester.run('require-valid-default-prop', rule, {
}`,
parserOptions,
errors: errorMessage('string')
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Array as PropType<string[]>,
default: []
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Object as PropType<{ [key: number]: number }>,
default: {}
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
},
{
filename: 'test.vue',
code: `export default Vue.extend({
props: {
foo: {
type: Function as PropType<() => number>,
default: 10
}
}
});
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: require.resolve('@typescript-eslint/parser'),
errors: errorMessage('function')
}
]
})