IntelliSense with VS Code - what about THIS

Hi all.

I am tryingt to get intelliSense to work with VS Code. A am new with Phaser and JS.

I am working with the Phaser tutorial “Making your first Phaser game

I alread read different posts about intelliSense and VS Code (here in the forum too) and intelliSence seems to work:

phaser_vscode_intellisense_works

But not with THIS:

phaser_vscode_intellisense_works_not

And it does not work with anything inside functions what uses THIS:

phaser_vscode_intellisense_works_fct

But inside a function:

phaser_vscode_intellisense_works_not_fct

So why ist it like this? Do I make a mistake or do not understand something?

Thancs for your help in advance,

panic.zero

tl;dr:

class MyScene extends Phaser.Scene {
//..
 preload(){
   // intelliSence will work here
 }
}

first of all, in general, and specially if you are using webpack, you probably want to have a jsconfig file. You probably may want to use a tsconfig file instead if you want to use Typescript in your project.

Think for two seconds about why intellisense isn’t working: all you have is a function, preload and you haven’t told anyone anything about it.

If I just open up a file and add a function preload, there is no way to infer anything about it.

Now, if you are writing typescript, you can always add type information. If you are writing javascript only, you can always use JSDoc annotations.

So ideally you just want to extend Phaser.Scene, like I did above. Things will be smooth enough to infer what you meant if you go that route. If you don’t want to do that, you probably (not 100% sure) can simply add a JSDoc comment with a @this tag.

Tell me if that makes sense. Good luck!

1 Like

Hi Idd.

Thank you very much for your answer.
The annotation @this works fine. I experimented a bit with annotations but I think it will make it quite complicated.
So I think I will give TypeScript a chance.

Regards,
panic.zero