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

Refactor extractProfileFeatures #14

Open
tshemsedinov opened this issue Mar 16, 2024 · 1 comment
Open

Refactor extractProfileFeatures #14

tshemsedinov opened this issue Mar 16, 2024 · 1 comment

Comments

@tshemsedinov
Copy link

Instead of

export function extractProfileFeatures(session: UserSession | EResidentSession): ProfileFeature[] {
if (!('features' in session) || !session.features) {
return []
}
return profileFeaturesToList(session.features)
}

consider following:

export function extractProfileFeatures(session: UserSession | EResidentSession): ProfileFeature[] {
    if (!Object.hasOwn(session, 'features')) return []
    return profileFeaturesToList(session.features)
}

It is also not ok to have such an uncertain union type UserSession | EResidentSession, may we change it to certain single interface?

@bohdansec
Copy link

bohdansec commented Mar 16, 2024

Замість коду, який ви запропонували, хочу запропонувати свій варіант — він коротший та елегантніший.

export function extractProfileFeatures(session: UserSession | EResidentSession): ProfileFeature[] {
    return Object.hasOwn(session, 'features') ? profileFeaturesToList(session.features) : [];
}

Але тут ще можна дуже багато покращити.
Можливо, мій варіант більше підійде розробнику.

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

2 participants