-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor: 可読性のため一部でArray.prototype.at
を使うように
#11274
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #11274 +/- ##
===========================================
+ Coverage 77.64% 77.72% +0.08%
===========================================
Files 908 739 -169
Lines 91878 70787 -21091
Branches 7670 7233 -437
===========================================
- Hits 71335 55018 -16317
+ Misses 20543 15769 -4774
|
👍 |
もうマージされちゃったけど |
指摘を受けて調べてみたところ、たしかにそのような話がある(あった)ようでした。
ただ実際に自分でも簡単なベンチマークを実行してみたところ、少なくとも現在の最新バージョンのMisskey( 現在LTSである LTSでパフォーマンス問題が起きてしまっているのは少し残念ですが、Misskeyが公式にサポートしているバージョンではないため問題はない、ということで構いませんか? |
そうなのかしら |
公式にサポートしてるバージョンではあるけど推奨バージョンではない |
すみません、間違えました。CHANGELOGには「 私が「サポートされているNode.jsのバージョン」と誤認してしまったのは、 話を脱線させてしまうようで申し訳ないのですが、「サポートしているものの推奨はしておらず、それゆえテストの実行で使われていないバージョンのNode.js」にはまだない機能を開発時に誤って使用してしまったとき、そのミスを知ることができる仕組みはありますか? 今回の あとfrontendの存在をすっかり忘れてしまっていました。frontendでどのようなpolyfillが挿入されているのかまだ理解できていないのですが、やはり Misskey開発でこの辺りがどのようになっているのか詳しくないので申し訳ないです。 |
* refactor: `Array.prototype.at`を使うように * fixup! refactor: `Array.prototype.at`を使うように
)" This reverts commit 2b6dbd4.
* Revert "refactor: 可読性のため一部で`Array.prototype.at`を使うように (misskey-dev#11274)" This reverts commit 2b6dbd4. * Apply suggestions from code review --------- Co-authored-by: okayurisotto <okayurisotto@proton.me>
What
items[items.length - 1]
のようにしている部分をitems.at(-1)
のように書き換えました。Why
可読性をより良くするため。
Additional info (optional)
型が
T[]
である配列に対してArray.prototype.at()
を実行すると、返り値の型はT | undefined
になります。これまでのブラケット記法でのアクセスでは常にT
が返されていたため1、このPRではundefined
でないかどうかの確認を行う処理も、簡単に追加できそうな部分に関しては追加しています。ただ簡単には追加できそうにない部分もあったため、そちらでは暫定的にnon-null assertionを使ってしまっています。追加しようにも変更が大きくなってしまいそうで、このPRにすべての変更を含めてしまうのはよくないのではないかというように判断しました。
Checklist
Footnotes
https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess が有効になっていないため ↩