2

I'm writing a web app using Angular 10 in the frontend and Parse-Server in the backend.

I would like to use Typescript instead of Javascript for writing all my cloud code functions and jobs, but I'm a bit unsure how to set it up, in Angular everything is "natively" Typescript so no set up needed there.

There's remarkable little information out there on how to set up Typescript with Parse. All I found was this incomplete medium article: https://medium.com/@avifatal/using-parseplatform-cloud-code-with-typescript-d27ded2e5054

How do I set up Typescript instead of Javascript for writing cloud code in parse-server?

1
  • 1
    The reason you find an absence of information is that TypeScript is designed to work in any context where JavaScript works, you just need to compile it. Angular is very much an outlier here. Commented Jul 10, 2020 at 14:07

2 Answers 2

4

I'm not familiar with Angular, but I wrote many projects in TypeScript that use both Parse Server and the Parse SDK for JavaScript.

The Parse Server itself don't have any type definitions, so in order to use it in your project you must make sure to create a type definition file somewhere in your project folder (index.d.ts) and declare the module to the Parse Server, like this:

declare module 'parse-server'

But don't expect intelligent code completion in this case.

But if you are using the Parse SDK for JS then everything is much easier because you just need to import the package @types/parse in your package.json (alongside with the parse package) and everything should work out of the box in your TypeScript code.

If you need an example, I use cloud code in my Parse Server in that you can find in this repo. Look at the folder src/cloud.ts.

Sign up to request clarification or add additional context in comments.

Comments

0

What I can tell you from the experience I have with our customers using Typescript on SashiDo is that since Typescript is a superset of JavaScript that is compiled to JavaScript, you can definitely use it in Cloud Code. You'll need to supply the compiled JavaScript files to be load in the cloud code as regular JS files.

You do not need to require Parse JS SDK as it is exposed as a global variable to make it easier to use and initialize it for you.

Please note that this would work only on parse server version 2.8.4 and above.

You can also put the build on postinstall and your code needs to go in the cloud directory and you need to have a main.js in there. This way you can store the .ts file on the repo and ignore the js files.

Here is an example for postinstall: "postinstall": "npm run build"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.