Moralis Typescript Questions

The Moralis types don’t match the examples and the documentation, for example with react-moralis there should be the authenticate function from the “useMoralis” hook, and based on the documentation it could be used like:

"authenticate({ provider: 'metamask' })"

Only if I do it, I get compilation errors - but if I ignore the types, it works fine! indicating the the types don’t match the actual code!

Provider cannot be passed to moralis based on the types, the types for the options object passed to it are:
export interface AuthenticateOptions { onError?: (error: Error) => void; onSuccess?: (user: MoralisType.User) => void; onComplete?: () => void; throwOnError?: boolean; type?: AuthType; connector?: MoralisType.Connector; chainId?: number; signingMessage?: string; }

And that makes working with moralis and typescript, a very bad experience!


we will improve over time, did you try with latest version?

Yea (v1.0.3), also thought of dropping moralis-react and found out the moralis SDK is even worse…
authenticate doesn’t even exists based on the types…

I think I’ll go back to using alchemy, moralis is nice and all, but with no proper types I don’t see a way to even integrate the SDK into our typescript project :confounded:

Property ‘authenticate’ does not exist on type ‘typeof Moralis’.ts(2339)

1 Like

We try to do our best with Typescript support because we love it as well.

  • Will release a fix for react-moralis in a bit, this typing has been lost due to the v1 release
  • For Moralis.authenticate, the typing is currently only working for Moralis.Web3.authenticate (both functions do the same). Will also release a fix for this, as Moralis.authenticate is recommended over Moralis.Web3.authenticate

Please let us know if you encounter any more issues with Typescript, we do our best to make it fully supported.

The next major release of the SDK will probably be written completely in Typescript, to avoid missing types in the future :slight_smile:


Should be a better experience in

  • moralis v1.0.6
  • react-moralis v1.0.3

Actually yea, it’s much better now =)
I saw Moralis 1.0.7 came out, the types issues I had are solved :smiley:


Hi there,

i have some newbie issues:

How can i create a dex in angular? Following tutorial seems like await Moralis.Plugins.oneInch.getSupportedTokens doesn’t work in .ts. When i try in .js like tutorial, it doesn’t type though it works… Some way to do it in Angular?


1 Like

Found a new issue!
Bit weird to deprecate something, without giving an alternative…

1 Like

Moralis.enable has been deprecated already for a while, not sure why it did not show up in your IDE.
Instead you can use enableWeb3: Moralis.enableWeb3


Then it makes sense to add it to the deprecation message like:

@deprecated: use Moralis.enableWeb3 instead

Which would make it easier to understand,

In the end I’m following the moralis blog and videos and they use deprecated API’s but it’s hard to understand what to use instead if the messages are not helpful.

1 Like