This is a template you can use to setup your node-hill project with TypeScript Follow the Setup guide right below
- Download Node.js 8 or above at https://nodejs.org/en/download/
- Download THIS template by pressing green
Codebutton and downloading ZIP file. - Open the extracted folder in the file explorer, and in the top bar type "cmd" and press enter.
- Download TypeScript at https://www.typescriptlang.org/download
- Run
npm i node-hill@latest, as this will install the needed dependencies for node-hill to function. - Run
npm i node-hill-types@latest, as this will install the node-hill type definitions for TypeScript to function. - Edit the start.js file to fill in your appropriate server information. You will need to add your host key for the set you want to host. This can be found under the set's settings page.
- Edit your game code in
./user_scripts.ts/folder. - Launch
typescript_compiler.bat, this will open up a terminal. Everytime you save any file inside./user_scripts.ts/it will recompile the JavaScript The code will get compiled ONLY WHEN THAT TERMINAL IS OPENED, CLOSING THE TERMINAL WILL STOP COMPILING THE TYPESCRIPT CODE If after launching thetypescript_compiler.batterminal will immediately close, then make sure you correctly downloaded the TypeScript - The project is all yours now! You can now launch the server and client and test out the TypeScript!
- At least 1 TypeScript file should contain
import {} from "node-hill-types" - Edit game code ONLY in
./user_scripts.ts/, the./user_scripts/will be automatically compiled (as long astypescript_compiler.batis running) - Always have
typescript_compiler.batopened for code compilation, also remember that code is being compiled only when the file with code is saved - If you run into a problem when code that would compile in JavaScript, but for some reason doesn't, you can use
//@ts-expect-errorabove the error. Not the best solution, but a quick fix. - You can use Enums!
GameEvents.InitialSpawnas an example. - If you find an issue with the npm module, message me on discord.
I really recommend to use Visual Studio Code, since it has a built it IntelliSense for TypeScript. So continuing from where we left of:
- Download VSCode at https://code.visualstudio.com/
- Right click on the template folder and select
Open with Code - In VSCode do the `Ctrl + `` key combo to open up the terminal
- In the terminal paste
./typescript_compiler.bat, which will just run the bat file inside VSCode, which allow you to see the errors in your TypeScript code, without a need to switch between VSCode and the terminal in separate window. - And that's it! AFAIK, VSCode is already configured for using TypeScript, so enjoy!