Typescript Version

Hi,

I have the following typescript error on the moralis library. I suspect it’s a typescript compatibility issue. Just curious which version of typescript should I use to go with the Moralis library. Thank ou

TypeScript error in node_modules/@moralisweb3/core/lib/utils/toCamelCase.d.ts(1,62):
Type expected.  TS1110

  > 1 | declare type CamelCase<Input extends string> = Input extends `${infer P1}_${infer P2}${infer P3}` ? `${P1}${Uppercase<P2>}${CamelCase<P3>}` : Input;
      |                                                              ^
    2 | export declare type Camelize<Data> = {
    3 |     [Key in keyof Data as CamelCase<string & Key>]: Data[Key] extends Array<infer Value> ? Value extends {} ? Array<Camelize<Value>> : Data[Key] : Data[Key] extends {} ? Camelize<Data[Key]> : Data[Key];
    4 | };

What is the Moralis code you’re using that leads to a type error?

import Moralis from ‘moralis’

:joy:

No other code? Which moralis version? Can you post your package.json.

{
  "name": "interface",
  "version": "1.0.0",
  "description": "Interface",
  "homepage": ".",
  "engines": {
    "node": ">=14.17.0"
  },
  "private": true,
  "devDependencies": {
    "@ethersproject/experimental": "^5.0.1",
    "@reduxjs/toolkit": "^1.3.5",
    "@types/node": "^13.13.5",
    "@types/numeral": "^2.0.2",
    "@types/react": "^16.9.34",
    "@types/react-custom-scrollbars": "^4.0.9",
    "@types/react-dom": "^16.9.7",
    "@types/react-html-parser": "^2.0.2",
    "@types/react-redux": "^7.1.8",
    "@types/react-router-dom": "^5.0.0",
    "@types/react-slick": "^0.23.7",
    "@types/react-virtualized-auto-sizer": "^1.0.0",
    "@types/react-window": "^1.8.2",
    "@types/rebass": "^4.0.5",
    "@types/styled-components": "^5.1.0",
    "@types/testing-library__cypress": "^5.0.5",
    "@types/wcag-contrast": "^3.0.0",
    "@typescript-eslint/eslint-plugin": "^2.31.0",
    "@typescript-eslint/parser": "^2.31.0",
    "@web3-react/core": "^6.0.9",
    "@web3-react/fortmatic-connector": "^6.0.9",
    "@web3-react/portis-connector": "^6.0.9",
    "@web3-react/walletconnect-connector": "^6.1.1",
    "@web3-react/walletlink-connector": "^6.2.11",
    "babel-plugin-styled-components": "^2.0.2",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^4.0.0",
    "ethereum-blockies-base64": "^1.0.2",
    "ethers": "^5.0.7",
    "node-vibrant": "^3.1.5",
    "prettier": "^1.17.0",
    "react": "^16.13.1",
    "react-device-detect": "^1.6.2",
    "react-dom": "^16.13.1",
    "react-html-parser": "^2.0.2",
    "react-markdown": "^4.3.1",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.0.0",
    "react-scripts": "^3.4.1",
    "redux-localstorage-simple": "^2.3.1",
    "styled-components": "^4.2.0",
    "typescript": "^3.8.3"
  },
  "resolutions": {
    "@walletconnect/web3-provider": "1.1.1-alpha.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "serve": "serve build -l 3000",
    "integration-test": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run'"
  },
  "eslintConfig": {
    "extends": "react-app",
    "ignorePatterns": [
      "node_modules"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "license": "GPL-3.0-or-later",
  "dependencies": {
    "@types/big.js": "^6.1.3",
    "@types/crypto-js": "^4.0.2",
    "@types/react-datetime-picker": "^3.4.1",
    "@types/react-portal": "^4.0.4",
    "@walletconnect/web3-provider": "^1.7.1",
    "@web3auth/web3auth": "^0.2.4",
    "crypto-js": "^4.0.0",
    "jsbi": "^4.1.0",
    "moralis": "^2.7.1",
    "react-datetime-picker": "^3.5.0",
    "react-portal": "^4.2.1",
    "toformat": "^2.0.0"
  }
}

Is this with an old project or boilerplate? You are using fairly old versions of typescript, react, etc. You could try updating typescript to something recent like 4.7.4.

But there may be other issues due to your older dependencies.

exactly. everything worked fairly well with your moralis v1 till the recent release of moralis v2. We’d like to make the switch without dealing with the dependecy hell.

If you want to use moralis-v1, you need to use that version instead:

npm install moralis-v1 
// or
yarn add moralis-v1

You’re using [email protected] which is for v2.

Switching to V2 is a conscious decision as V1 is the foster child that might surprise us in the future. Does the team have any plan to make v2 more backward compatible besides upgrading the entire dependencies from the user’s side?

No v2 (moralis@2+) is fundamentally a different library which is what you should use if you’re using your own backend.

moralis-v1 and react-moralis is what you can keep using for Moralis servers (hosted or self-hosted).

Thank you. But I don’t see the “servers” option on the console side panel anymore. I thought v1 is deprecated already.

That means new servers can’t be created anymore. That option/tab will show if you have a server(s). You will need to self host if you don’t have one.