Skip to content

Commit

Permalink
Merge pull request #26 from cwyyue/feat-propType-test-doc
Browse files Browse the repository at this point in the history
feat: props支持ts
  • Loading branch information
pagnkelly authored Jul 5, 2024
2 parents d915030 + 5721775 commit 432bf26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/rules/valid-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ description: 校验properties有效值
}
}
})
// ✓ PropType ts
createComponent({
properties: {
propsA: {
type: String as PropType<Str>,
value: ""
},
propsB: Object as PropType<Obj>
}
})
// ✗ BAD
createComponent({
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/valid-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ function validProp(node, context, allowKeys) {
})
}
} else if (
node.value.type !== 'Identifier' &&
node.value.type !== 'TSAsExpression'
!(node.value.type === 'Identifier' || node.value.type === 'TSAsExpression')
) {
return context.report({
node,
Expand Down
10 changes: 7 additions & 3 deletions tests/lib/rules/valid-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const tsParser = require.resolve('@typescript-eslint/parser')
const rule = require('../../../lib/rules/valid-properties')
const RuleTester = require('eslint').RuleTester

Expand Down Expand Up @@ -42,11 +42,15 @@ ruleTester.run('valid-properties', rule, {
type: String,
optionalTypes:[Number],
observer: ()=>{}
},
propsD: Object as PropType<Obj>,
propsE: {
type: Object as Obj
}
}
})
`
`,
parser: tsParser
},
{
filename: 'test.mpx',
Expand Down

0 comments on commit 432bf26

Please sign in to comment.