Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [no-inferrable-types] ignore optional props (#918)
  • Loading branch information
a-tarasyuk authored and bradzacher committed Aug 29, 2019
1 parent 29a01b8 commit a4e625f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-inferrable-types.ts
Expand Up @@ -250,7 +250,7 @@ export default util.createRule<Options, MessageIds>({
// Essentially a readonly property without a type
// will result in its value being the type, leading to
// compile errors if the type is stripped.
if (ignoreProperties || node.readonly) {
if (ignoreProperties || node.readonly || node.optional) {
return;
}
reportInferrableType(node, node.typeAnnotation, node.value);
Expand Down
Expand Up @@ -123,6 +123,15 @@ ruleTester.run('no-inferrable-types', rule, {
"class Foo { a: number = 5; b: boolean = true; c: string = 'foo'; }",
options: [{ ignoreProperties: true }],
},
{
code: `
class Foo {
a?: number = 5;
b?: boolean = true;
c?: string = 'foo';
}
`,
},
],

invalid: [
Expand Down

0 comments on commit a4e625f

Please sign in to comment.