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

AuthContext.tsx type definition is not compiling #5335

Closed
martdavidson opened this issue Oct 1, 2020 · 3 comments · Fixed by #5372
Closed

AuthContext.tsx type definition is not compiling #5335

martdavidson opened this issue Oct 1, 2020 · 3 comments · Fixed by #5372
Assignees
Labels

Comments

@martdavidson
Copy link

What you were expecting:
/ra-core/src/auth/AuthContext.tsx to be compilable

What happened instead:
Looks like defaultProvider is being instantiated with getIdentity: () => Promise.resolve(defaultIdentity), which has id: null. But the type definition for AuthProvider has a UserIdentity object which requires an id: Identifier.

Environment

  • React-admin version: 3.9.0-beta.3
  • React version: 10.13.1
@fzaninotto
Copy link
Member

I cannot reproduce the problem in master. Maybe the problem was fixed since the latest beta, or maybe you are having mixed dependencies (e.g. ra-core on an older version than react-admin).

Could you please create a CodeSandbox / repo reproducing the issue?

@martdavidson
Copy link
Author

Trying to track down the issue. I deleted yarn.lock and node_modules and did a fresh install, having the same issue:

TypeScript error in /node_modules/ra-core/src/auth/AuthContext.tsx(16,5):
Type '() => Promise<{ id: null; fullName: null; }>' is not assignable to type '() => Promise<UserIdentity>'.
  Type 'Promise<{ id: null; fullName: null; }>' is not assignable to type 'Promise<UserIdentity>'.
    Type '{ id: null; fullName: null; }' is not assignable to type 'UserIdentity'.
      Types of property 'id' are incompatible.
        Type 'null' is not assignable to type 'Key'.  TS2322

    14 |     checkError: () => Promise.resolve(),
    15 |     getPermissions: () => Promise.resolve(),
  > 16 |     getIdentity: () => Promise.resolve(defaultIdentity),
       |     ^
    17 | };
    18 | 
    19 | const AuthContext = createContext<AuthProvider>(defaultProvider);

Let me see if I can get a repo goin.

@fzaninotto
Copy link
Member

I can't reproduce the problem, maybe it's a matter of TypeScript version. How are you compiling the react-admin code?

Anyway, my TypeScript compilation should fail like yours, so I'm pushing a change... blindly.

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

Successfully merging a pull request may close this issue.

2 participants