本記事を対象とする人 TS,JSで極力letではなくconstを使うべきと思っている人 結論 ts-patternが便利 https://github.com/gvergnaud/ts-pattern 解説 何かのオブジェクトを参照して場合分けして、変数を定義したい場合があると思います 例 let platform = ''; if (game.name === 'ff3') { platform = 'fc'; } else if (game.name === 'ff4') { platform = 'sfc'; } const platform = (() => { if (game.name === 'ff3') { return 'fc'; } else if (game.name === 'ff4') { return 'sfc'; } return ''; })(); //--
![TypeScriptで条件分岐時の可読性の高い変数設定 - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/34c06c90ca7079830f78e55d022f5222c0998dc2/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZoPTMzNiZ0eHQ9VHlwZVNjcmlwdCVFMyU4MSVBNyVFNiU5RCVBMSVFNCVCQiVCNiVFNSU4OCU4NiVFNSVCMiU5MCVFNiU5OSU4MiVFMyU4MSVBRSVFNSU4RiVBRiVFOCVBQSVBRCVFNiU4MCVBNyVFMyU4MSVBRSVFOSVBQiU5OCVFMyU4MSU4NCVFNSVBNCU4OSVFNiU5NSVCMCVFOCVBOCVBRCVFNSVBRSU5QSZ0eHQtY29sb3I9JTIzMjEyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTU2JnR4dC1jbGlwPWVsbGlwc2lzJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9MjlmMWQzN2ZmNmE2OWZjM2E3OGYwMjAyODZjZTQxYzE%26mark-x%3D142%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTcxNiZ0eHQ9JTQwcnl1c2VpeWFyb3UmdHh0LWNvbG9yPSUyMzIxMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT0zMiZ0eHQtYWxpZ249bGVmdCUyQ3RvcCZzPTllNTZmYzQ4NjFhMWUzZDRkMjk1Y2Q2NWQyN2ViNzVk%26blend-x%3D142%26blend-y%3D491%26blend-mode%3Dnormal%26s%3D1b43ebe9007b351aae3e1c4d6af36163)