Apache NetBeans 12.4 and XAMPP

User avatar
binhlq
Posts: 378
Joined: Thu Apr 16, 2020 3:56 am

Typescript Formatting in Netbeans

Post by binhlq »

I have started to use typescript in netbeans. I have installed typescript plugin typescript-netbeans. This recogonises the typescript code. But the normal code formatting option (Alt + Shift + F) doesn't seem to work for typescript. Indentations have to done manually as of now. Is there any solution for it ?

Netbeans version - 10.0

Typescript plugin - 3.0.1

Answer

I tried this and it works fine for me using NetBeans 10. These are the steps I followed:

  • Install version 3.0.1 of the TypeScript Editor plugin you linked to:

    Image

  • Download and install TypeScript using npm install -g typescript:

    Image

  • Create a simple NetBeans project (File > New Project... > HTML5/JavaScript > HTML5/JS Application).

  • Create a TypeScript file (File > New File... > Other > TypeScript File) within the project.
  • In the TypeScript file just created, right click and select TypeScript Setup... from the context menu.
  • The TypeScript Setup dialog opens. Click Browse... and select the path of your Lib directory. In my case this was the directory C:\Users\johndoe\AppData\Roaming\npm\node_modules\typescript\lib (containing typescript.js) that I had just created using npm:

    Image

Once the setup process is complete, create some content in the TypeScript file which is poorly formatted:

Code: Select all

function                            greeter(person) {
return "Hello, "                     + person;
                            }
                          let user  =           "Jane User";

document.body.innerHTML          = greeter(user);

Press Alt + Shift + F to reformat the code:

Code: Select all

function greeter(person) {
    return "Hello, " + person;
}
let user = "Jane User";

document.body.innerHTML = greeter(user);

If you are still having problems, post any relevant messages from the NetBeans error log (View > IDE Log).

Notes:

  • You can configure the formatting to be performed automatically whenever you save the file: Tools > Options > Editor > On Save > Language: TypeScript:

    Image

  • Although there is no option to explicitly specify TypeScript formatting, you can specify that JavaScript formatting is to be used for your project by default, which should be appropriate most of the time. Select your project in the Projects panel, right click and select Formatting from the Categories list in the Project Properties window:

    Image


Post Reply

Return to “Lập trình ngôn ngữ PHP”