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

Rewrite with better semantics and readability #13

Open
tshemsedinov opened this issue Mar 16, 2024 · 2 comments
Open

Rewrite with better semantics and readability #13

tshemsedinov opened this issue Mar 16, 2024 · 2 comments

Comments

@tshemsedinov
Copy link

Code readability is terrible, forEach has different semantics, long expressions are totally unreadable

export function profileFeaturesToList(features: UserFeatures): ProfileFeature[] {
const featuresList: ProfileFeature[] = []
Object.entries(features).forEach(([key, value]: [string, unknown]) => value && featuresList.push(<ProfileFeature>key))
return featuresList.filter((feature) => {
if (feature !== ProfileFeature.office) {
return true
}
return features?.[feature]?.status === DiiaOfficeStatus.ACTIVE
})
}

Please consider at least:

export function profileFeaturesToList(features: UserFeatures): ProfileFeature[] {
    const featuresList: ProfileFeature[] = []

    const entries = Object.entries(features)
    for (const [key, value]: [string, unknown] of entries) {
      if (!value) continue
      featuresList.push(<ProfileFeature>key))
    }

    return featuresList.filter((feature) => {
        if (feature !== ProfileFeature.office) return true
        return features?.[feature]?.status === DiiaOfficeStatus.ACTIVE
    })
}
@bohdansec
Copy link

bohdansec commented Mar 16, 2024

image

У коді, який ви надали, є синтаксична помилка: ви додали зайву закриваючу дужку після <ProfileFeature>key

Також, у вашому коді є багато частин, які можна покращити. Наприклад, я рекомендую використовувати оператор as для приведення типів замість застарілого синтаксису з кутовими дужками, який ви використовували у вашому прикладі <ProfileFeature>key. Цей підхід є більш сучасним, безпечним і бажаним у TypeScript.

@vird
Copy link

vird commented Mar 17, 2024

#25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants