-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [explicit-function-return-type] allow as const
arrow functions
#876
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
Conversation
add an option `allowDirectConstAssertionInArrowFunctions` to allow bodyless arrow functions which return `as const`
Thanks for the PR, @Zzzen! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint |
as const
arrow functionsas const
arrow functions
as const
arrow functionsas const
arrow functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, sorry might have changed my mind:
Currently in this PR:
This would be fine:
const foo = () => {
return {
bar: true
} as const;
}
But this wouldn't:
function foo() {
return {
bar: true
} as const;
}
This feels very arbitrary to me... Why do we want to limit this to ArrowFunctionExpressions?
cc @bradzacher as you did also explicitly mention arrow functions on the original issue
IMO, this is tricky. function foo() {
return {
bar: true
} as const;
} should this one pass too? function foo() {
if (x) {
return { bar: true } as const;
} else {
return { foo: true } as const;
}
} |
@Zzzen Apologies, I was actually incorrect with my previous comment: const foo = () => {
return {
bar: true
} as const;
} This would not actually be ok with your PR, because the |
Codecov Report
@@ Coverage Diff @@
## master #876 +/- ##
==========================================
+ Coverage 94.16% 94.18% +0.01%
==========================================
Files 113 113
Lines 4870 4882 +12
Branches 1355 1361 +6
==========================================
+ Hits 4586 4598 +12
Misses 163 163
Partials 121 121
|
add an option
allowDirectConstAssertionInArrowFunctions
to allow bodyless arrow functions which returnas const
.closes #653