Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-inferrable-types] ignore optional properties #918

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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