Skip to content

ksenonadv/ragemp-types

 
 

Repository files navigation

Remember to 🌟 this Github if you 💖 it.

Types definitions for RAGE:MP (1.1+)

📥 Installation

Use github:leonardssh/ragemp-types#types-server to latest build

# With npm
npm i --save-dev github:leonardssh/ragemp-types#[email protected]

# With yarn
yarn add -D github:leonardssh/ragemp-types#[email protected]

# With pnpm
pnpm add -D github:leonardssh/ragemp-types#[email protected]

Use github:leonardssh/ragemp-types#types-client to latest build

# With npm
npm i --save-dev github:leonardssh/ragemp-types#[email protected]

# With yarn
yarn add -D github:leonardssh/ragemp-types#[email protected]

# With pnpm
pnpm add -D github:leonardssh/ragemp-types#[email protected]

Use github:leonardssh/ragemp-types#types-cef to latest build

# With npm
npm i --save-dev github:leonardssh/ragemp-types#[email protected]

# With yarn
yarn add -D github:leonardssh/ragemp-types#[email protected]

# With pnpm
pnpm add -D github:leonardssh/ragemp-types#[email protected]

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}/@ragemp/types-server"]
	}
}

🤓 Usage

❌ 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 github:leonardssh/ragemp-types#types-server
npm i --save-dev github:leonardssh/ragemp-types#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)
{
	// NOTE: This is my config that I use everywhere, it is optimized for the cleanest and best code.
	"exclude": ["node_modules", "dist"],
	"compileOnSave": true,
	"compilerOptions": {
		"skipLibCheck": false,
		"target": "esnext",
		"module": "esnext",
		"moduleResolution": "node",
		"lib": ["es6", "esnext", "DOM"],
		"rootDir": ".",
		"outDir": "dist",
		"strict": true,
		"removeComments": false,
		"noUnusedLocals": true,
		"noUnusedParameters": true,
		"noImplicitReturns": true,
		"noFallthroughCasesInSwitch": true,
		"allowSyntheticDefaultImports": true,
		"importHelpers": true,
		"esModuleInterop": true,
		"resolveJsonModule": true,
		"forceConsistentCasingInFileNames": true,
		"emitDecoratorMetadata": true,
		"experimentalDecorators": true,
		"allowJs": true,
		"declaration": false,
		"declarationMap": false,
		"sourceMap": false,
		"alwaysStrict": true,
		"importsNotUsedAsValues": "remove",
		"incremental": true,
		"newLine": "lf",
		"noEmitHelpers": true,
		"preserveConstEnums": true,
		"pretty": true,
		"useDefineForClassFields": true,
		"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]/@ragemp/types-client
		"types": ["../../node_modules/@ragemp/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]/@ragemp/types-server
		"types": ["../../node_modules/@ragemp/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.

About

Types definitions for RAGE:MP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published