How to use the .d.ts file? JavaScript autocompletion [Solved + Solution]

Hi,

I have a problem. I saw on the FiveM Documentation that there is a TypeScript file with the definitions of FiveM natives but i wonder how the hell i am supposed to use it? I know that I’m probably so dumb but I tried to google it and looked everywhere but there is really small amount of information about how to get it to work. Can somebody write me step-by-step instruction what to do to have those automatic completions in Sublime Text 3 or other editor? Thanks in advance!

// Edit:

After all I’ve finally made it to work so i decided to write an instruction how to setup JavaScript FiveM natives autocompletion in Visual Studio Code for other people:


1. Install Node.js
2. Install Visual Studio Code
3. Now run cmd.exe as Administrator and write those two commands:

npm install -g typescript

and

npm install -g typings

4. Now run cmd.exe and using “cd” go to your FiveM server data (this one with resources folder and server start file)
(It could be other folder but i prefer this one becouse it’s easy to access)
5. Create new directory and name it as you want. (You can create it normally by GUI or type mkdir in cmd)
6. Go to this directory using “cd”
7. Now being in this directory type “typings init” in your cmd.
8. It should create you an empty typings.json file.
9. Now in the same directory, you have to paste a few commands:

typings install file: PATH TO YOUR INDEX.D.TS FILE IN FIVEM SERVER DIRECTORY --save --global

In my case:

typings install file:C:\Users\karos64\Desktop\FiveM\citizen\scripting\v8\index.d.ts --save --global

Now you just want to paste the same command only changing the last file, we need to change index.d.ts to:

natives_0193d0af.d.ts
natives_server.d.ts
natives_blank.d.ts
natives_universal.d.ts

So in total you need to type 5 commands!
If you don’t get any errors in cmd during that everything will be fine!

10. Now go to your Visual Studio Code and to your existing (or create new) .js file. (This one in your resource folder, client or server side JS)

11. All you have to do is to paste this line at the top of your script! It has to be the first line!

/// <reference path="<PATH TO YOUR INDEX.D.TS FILE IN YOUR DIRECTORY>" />

I created an “autocompletion” folder in my FiveM server data folder so in my case the path look like:

“C:\Users\karos64\Desktop\FiveM Server Data\autocompletion\typings\index.d.ts”

12. That’s all! You should have FiveM natives autocompletion in your VSC! But don’t forget to add this one line at the beggining of every JavaScript file!

Here are examples of how to use natives in Javascript

http://docs.fivem.net/scripting/javascript/

What I posted above is actually not what you want. I will have a look around for you on how to get this working on Visual Studio Code.

Edit:

I think what you will have to do is reference the natives_universal.d.ts on top of your js file like so:

/// <reference path=”../../typings/index.d.ts” />

Source: https://medium.com/front-end-hacking/including-typescript-definitions-in-a-non-typescript-project-using-visual-studio-code-vsc-eac62765fd

1 Like

Hi, thanks for response.
I tried to install this on Visual Studio Code but when i type

$ typings install <nameOfLibrary> --save

(I also tried a lot of different combination this command (with --global, dt~, etc.))
Visual says that this file is not in the registry. It also says that i can help with adding this typings to the registry by going on their github page: https://github.com/typings/registry So i guess i can install only those files that are in registry. Maybe you know how can I bypass this or maybe there is someone that could add this .d.ts file to registry?

Can’t you just point the reference path to the absolute path of the .d.ts that you want to use? So in this case the location in the FiveM app data?

1 Like

Unfortunately no, it’s doing nothing :confused:

Hi!

I’ve finally made it to work!
It took me about 3-4 hours of searching and trying.
I will try to make a new topic with instruction how to setup this JavaScript autocompletion in Visual Studio Code so other people can use it.
Anyway thanks for everything, it really helps a lot!

//Edit
Ok so i can’t create a topic in Server Tutorials so i will post this instruction here when i end so somebody might want to pin it or sth.

1 Like

I can move it for you once I see it. Post it in #server-development:server-discussion or so.

It may also be appropriate in #development:tutorials

1 Like

Oh great! If you could do it and my topic is suitable, it would be very nice of you :smiley: i edited the main post and put the instructions there.

Moved to #development:tutorials

This topic was first a question, but OP found the solution and changed this topic in to a tutorial.

1 Like