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!

2 Likes

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:

3 Likes

Should be a better experience in

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

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

2 Likes

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?

Thanks,

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

3 Likes

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