Using Typescript

From RAGE Multiplayer Wiki
Revision as of 18:44, 22 April 2024 by Shr0x (talk | contribs) (Updates)


Information

Typescript is a really great resource for C# users looking for a similar language for writing client-side resources.

Luckily for us there are a few users out there who have created Typescript definitions for the client-side code.

You may obtain them from:

RAGEMP Type Definitions


Prerequisites

Setup

Open Visual Studio Code

Pressing ctrl + ` (or by going to File > Terminal > New terminal) will open a terminal.

Initialize a new Nodejs project by running the commands below in your terminal:

npm init

Or for a quick setup:

npm init -y

After you're done initializing the new nodejs project, execute the command below to install typescript:

npm install -g typescript

To verify that you have installed typescript correctly type:

tsc --version

Adding Typescript Definitions

Client-Side

# With npm
> npm i --save-dev @ragempcommunity/types-client

# With yarn
> yarn add -D @ragempcommunity/types-client

# With pnpm
> pnpm add -D @ragempcommunity/types-client

Server-Side

# With npm
> npm i --save-dev @ragempcommunity/types-server

# With yarn
> yarn add -D @ragempcommunity/types-server

# With pnpm
> pnpm add -D @ragempcommunity/types-server

If neither of these happen to be working properly you can try removing -g. That's just a global install function.


You can verify if it's working properly by creating a new Typescript file. .ts

Then begin programming by typing:

mp.game

If working properly you will have auto-fill available.

Workspace Help

When you're working with Typescript you want your workspace to be setup in clientside_resources.

You can do this by going to: File -> Open Folder -> clientside_resources

After you should initialize your typescript directory by doing Ctrl + ` and typing tsc --init.

If done correctly you will have a tsconfig.json


Compiling your Typescript Files

You mainly want to do this through your command prompt. You can open up a prompt in Visual Studio Code by press Ctrl + `.

This will allow you to easily type tsc

If done properly you will see newly compiled JavaScript files available in the same directory as the files you have created.