Skip to content

Commit 1183f8f

Browse files
add new test case
1 parent 9264f63 commit 1183f8f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/rules/force-types-on-object-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = {
9191
if (isLooksLike(prop.value, { type: 'Identifier', name: 'Object' })) {
9292
context.report({
9393
node: prop,
94-
message: 'Object props has to contains type.'
94+
message: 'Expected type annotation on object prop.'
9595
})
9696
}
9797
if (prop.value.type === 'TSAsExpression') {

tests/lib/rules/force-types-on-object-props.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,54 @@ ruleTester.run('force-types-on-object-props', rule, {
4444
}
4545
</script>
4646
`,
47-
template('type: Object as Prop<{}>'),
4847
template('type: String'),
48+
template('foo: String,'),
4949
template('type: Number'),
5050
template('type: Boolean'),
51-
template('type: [String, Number, Boolean]')
51+
template('type: [String, Number, Boolean]'),
52+
template('foo: someFunction(),'),
53+
template('foo: { type: Object as () => User }'),
54+
template('type: Object as Prop<{}>'),
55+
template('foo: { type: Object as PropType<User> },'),
5256
],
5357
invalid: [
5458
{
5559
code: template('type: Object'),
5660
errors: [
5761
{
58-
message: 'Object props has to contains type.'
62+
message: 'Expected type annotation on object prop.'
5963
}
6064
]
6165
},
6266
{
6367
code: template('type: Object as any'),
6468
errors: [
6569
{
66-
message: 'Object props has to contains type.'
70+
message: 'Expected type annotation on object prop.'
6771
}
6872
]
6973
},
7074
{
7175
code: template('type: Object as {}'),
7276
errors: [
7377
{
74-
message: 'Object props has to contains type.'
78+
message: 'Expected type annotation on object prop.'
7579
}
7680
]
7781
},
7882
{
7983
code: template('type: Object as unknown'),
8084
errors: [
8185
{
82-
message: 'Object props has to contains type.'
86+
message: 'Expected type annotation on object prop.'
8387
}
8488
]
8589
},
8690
{
8791
code: template('type: Object as string'),
8892
errors: [
8993
{
90-
message: 'Object props has to contains type.'
94+
message: 'Expected type annotation on object prop.'
9195
}
9296
]
9397
}

0 commit comments

Comments
 (0)