Open
Description
I try to pass a custom extractScopes function looking like this:
useGenericAuth({
/.../
extractScopes: (user) => user?.roles?.map((role) => `read:${role}`) ?? [],
}),
The first '?' triggers the linter rule: eslint@typescript-eslint/no-unnecessary-condition, which makes sense when I look at the type of extractScopes. UserType extends {} so there's no way it can be null.
Then I checked the source for the default extractScopes implementation, and the first thing it does is check for null:
export function defaultExtractScopes<UserType>(user: UserType): string[] {
if (user != null && typeof user === 'object' && 'scope' in user) {
if (typeof user.scope === 'string') {
return user.scope.split(' ');
}
if (Array.isArray(user.scope)) {
return user.scope;
}
}
return [];
}
Am I missing somehting? (probably). How can you use extractScopes in TS?
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels