graphql-hive / graphql-hive/envelop

useGenericAuth extractScopes type declaration is incorrect

Open
#2,573 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

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(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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.