Skip to content

ragempcommunity/ragemp-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Community-driven type definitions for RAGE Multiplayer

NPM version NPM Downloads Continuous Delivery - Server

NPM version NPM Downloads Continuous Delivery - Client

NPM version NPM Downloads Continuous Delivery - CEF

Twitter Discord Server

Remember to 🌟 this GitHub if you πŸ’– it.

πŸ“₯ Installation

πŸ”₯ Use github:ragempcommunity/ragemp-types#types-server to latest build

# 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

πŸ”₯ Use github:ragempcommunity/ragemp-types#types-client to latest build

# 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

πŸ”₯ Use github:ragempcommunity/ragemp-types#types-cef to latest build

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

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

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

πŸ€“ Usage

To make these types detectable, you need to add the types property below to tsconfig.json on each side of your project.

// e.g server-side
{
 "compilerOptions": {
  "types": ["{RELATIVE_PATH_TO_NODE_MODULES}/@ragempcommunity/types-server"]
 }
}

❌ Avoiding Conflict between Server <-> Client Types

To avoid conflicts between server and client types, they must be installed and set as follows:

Step #1: install the types in package.json from the project root

> npm i --save-dev @ragempcommunity/types-server
> npm i --save-dev @ragempcommunity/types-client

Step #2: for this step, your project should be structured as follows:

β”œβ”€β”€β”€my-awesome-ragemp-server
β”‚   └───src
β”‚        # Server - Contains code relating to the database, player spawning, etc.
β”‚        # Client - Contains code to display things to the user and do things to them.
β”‚         β”œβ”€β”€β”€client
β”‚          β”‚   β”œβ”€β”€β”€@types
β”‚          β”‚   β”‚   └───index.d.ts
β”‚          β”‚   β”œβ”€β”€β”€src
β”‚          β”‚   └───tsconfig.json
β”‚          β”‚
β”‚         server
β”‚    β”‚   β”œβ”€β”€β”€@types
β”‚     β”‚   β”‚   └───index.d.ts
β”‚          β”‚   β”œβ”€β”€β”€src
β”‚          β”‚   └───tsconfig.json
β”‚          └───
β”œβ”€β”€β”€package.json
└───tsconfig.base.json

Now that we know what our server structure should look like, let's start setting the types properly.

  1. tsconfig.base.json - this is our base tsconfig, from which we extend the client/server part (to avoid making redundant code)
{
 "exclude": ["node_modules", "dist"],
 "compileOnSave": true,
 "compilerOptions": {
  "target": "esnext",
  "module": "esnext",
  "moduleResolution": "node",
  "lib": ["es6", "esnext", "DOM"],
  "rootDir": ".",
  "outDir": "dist",
  "baseUrl": "./"
 }
}
  1. client/tsconfig.json - this is our tsconfig for the client side, extended from the basic tsconfig and containing the types for the client
{
 // NOTE: This tsconfig will work assuming your project is structured as described above.
 "extends": "../../tsconfig.base.json",
 "compilerOptions": {
  // [RELATIVE_PATH_TO_NODE_MODULES]/@ragempcommunity/types-client
  "types": ["../../node_modules/@ragempcommunity/types-client", "./@types"]
 },
 "include": ["./**/*.ts"]
}
  1. server/tsconfig.json - this is our tsconfig for the server side, extended from the basic tsconfig and containing the types for the server
{
 // NOTE: This tsconfig will work assuming your project is structured as described above.
 "extends": "../../tsconfig.base.json",
 "compilerOptions": {
  // [RELATIVE_PATH_TO_NODE_MODULES]/@ragempcommunity/types-server
  "types": ["../../node_modules/@ragempcommunity/types-server", "./@types"]
 },
 "include": ["./**/*.ts"]
}

For those who didn't understand, I made a gamemode from which you can better orient yourself:

ragemp-typescript & ragemp-javascript

πŸ‘¨β€πŸ’» Contributing

To contribute to this repository, feel free to create a new fork of the repository and submit a pull request.

  1. Fork / Clone and select the main branch.
  2. Create a new branch in your fork.
  3. Make your changes.
  4. Commit your changes and push them.
  5. Submit a Pull Request here!

πŸŽ‰ Thanks

πŸ“‹ License

This project is licensed under the MIT License β€” see the LICENSE file for details.