You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can now proceed directly to step 6 in the [Setting Up a Working Directory for Your Script](#setting-working-directory) section to configure TypeScript.
27
+
27
28
## Setting Up Your Development Tools {#setting}
28
29
29
30
To set up your development tools, follow these steps:
30
31
31
-
1.Install the latest LTS version of [Node.js](https://nodejs.org/). If you need to download it, you can find it on [this page](https://nodejs.org/en/download/releases/).
32
+
1.Download and install the latest LTS version of [Node.js](https://nodejs.org/en/download).
32
33
33
34
2. Open a terminal (on Windows, [Command Prompt](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands)) and run the following command:
34
35
35
36
```bash
36
37
$ node --version
37
-
v18.20.8
38
-
```
39
-
40
-
For Debian-based Linux distributions such as Ubuntu, please refer to [NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions#user-content-installation-instructions) to properly set up your apt-get sources.
41
-
42
-
In the rest of the how-tos, in blocks such as the above, lines starting with a `$` represent commands to type into a terminal. Sometimes a line follows without a $, represents output of the command.
43
-
44
-
3. Install [Visual Studio Code](https://code.visualstudio.com/) (not to be confused with Visual Studio), a text editor/IDE with good support for [TypeScript](https://www.typescriptlang.org/). Make sure you have a recent version (v1.11.0+); check the version you are using through Help > About when you have Code opened.
45
-
4. Install TypeScript 4.6.2 or higher with [`npm`](https://www.npmjs.com/) (or [`yarn`](https://yarnpkg.com/)), Node.js's package manager:
46
-
47
-
```bash
48
-
$ npm install -g typescript
38
+
v22.15.0
49
39
```
50
40
51
-
5. Use the following command to check the TypeScript compiler version on your PATH:
41
+
For Debian-based Linux distributions such as Ubuntu, refer to [NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions#user-content-installation-instructions) to properly set up your apt-get sources.
52
42
53
-
```bash
54
-
$ tsc --version
55
-
Version 4.6.2 (or higher)
56
-
```
43
+
In the rest of the how-tos, in code blocks such as the above, lines starting with a `$` represent the commands you should type into a terminal. Lines without `$` immediately following a command represent the output produced by that command.
57
44
58
-
If the version number is much lower, it could be that you also have an outdated TypeScript SDK on your system, left over from a previous installation. You can either uninstall the old TypeScript SDK, or bypass it by removing the old TypeScript SDK from your system's PATH environment variable.
45
+
3. Install [Visual Studio Code](https://code.visualstudio.com/) (VS Code: not to be confused with Visual Studio), a text editor/IDE with good support for [TypeScript](https://www.typescriptlang.org/). Make sure you have a recent version (v1.11.0+). Check the version you are using through **Help > About** when you have VS Code opened.
59
46
60
-
## Setting Up a Working Directory for Your Script
47
+
## Setting Up a Working Directory for Your Script {#setting-working-directory}
61
48
62
49
To set up a working directory for your script, follow these steps:
63
50
@@ -71,50 +58,61 @@ To set up a working directory for your script, follow these steps:
71
58
72
59
Visual Studio Code, other than Visual Studio, works with directories instead of project files.
73
60
74
-
2. Start **Visual Studio Code** and open the directory you just created. You can open a new instance of Code from the command line with the directory you want to open as first argument. For example, if your current working directory in your terminal is the directory in which all your project files live, use the following command to open Code:
61
+
2. Start Visual Studio Code and open the directory you just created. You can open a new instance of VS Code from the command line with the directory you want to open as first argument. For example, if your current working directory in your terminal is the directory in which all your project files live, use the following command to open VS Code:
75
62
76
63
```bash
77
64
$ code .
78
65
```
79
66
80
-
3. Add `mendixmodelsdk`, and `mendixplatformsdk` as dependencies.
67
+
3. Add `mendixmodelsdk` and `mendixplatformsdk` as dependencies.
81
68
Dependencies are stored in the `node_modules` directory (which will be automatically created by `npm`if necessary). Open the *package.json* you just created. Add a [`dependencies` block](https://docs.npmjs.com/files/package.json#dependencies) that looks like this:
82
69
83
70
```json
84
71
"dependencies": {
85
-
"mendixmodelsdk": "^4.56.0",
86
-
"mendixplatformsdk": "^5.0.0"
72
+
"mendixmodelsdk": "^4.102.0",
73
+
"mendixplatformsdk": "^5.2.0"
87
74
}
88
75
```
89
76
90
-
When a new major version of the Mendix SDK is released (as in, 1.0.0 to 2.0.0) and you run `npm update`in your project folder, the `^`in front of the version number makes sure that the installed version of the SDK will not be upgraded automatically. Only minor and patch releases (as in, 1.1.1) of the SDK will be automatically upgraded; otherwise, your script could inadvertently be broken. You may, of course, edit the dependency by hand yourself.
77
+
When a new major version of the Mendix SDK is released (as in, 1.0.0 to 2.0.0) and you run `npm update`in your project folder, the `^`in front of the version number makes sure that the installed version of the SDK is not upgraded automatically. Only minor and patch releases (as in, 1.1.1) of the SDK will be automatically upgraded; otherwise, your script could inadvertently be broken. You may, of course, edit the dependency yourself.
78
+
79
+
4. Add `typescript` and `@types/node` as dev dependencies.
80
+
Packages like TypeScript, testing libraries, linters, and type definitions (@types/...) are not required foryour app to runin production—they are only needed while writing and testing code.
81
+
82
+
```json
83
+
"devDependencies": {
84
+
"typescript": "~4.6.2",
85
+
"@types/node": "^22.0.3"
86
+
}
87
+
```
91
88
92
-
4. Save your changes and thenexecute the following to install the dependencies:
89
+
5. Save your changes and thenrun the followingcommand to install the dependencies:
93
90
94
91
```bash
95
92
$ npm install
96
93
```
97
94
98
95
If you are using version control, make sure to ignore the `node_modules` directory, otherwise you end up committing dependencies.
99
96
100
-
5. In Code, create a [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file next to your *package.json*. The *tsconfig.json* file is used by the TypeScript compiler to compile your code inthe proper manner to a JS file. Create it with the following contents.
97
+
6. In VS Code, create a [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file in the same directory of *package.json*. The *tsconfig.json* file is used by the TypeScript compiler to compile your code ina proper manner to a JavaScript file. Add the following contents to the *tsconfig.json* file:
101
98
102
99
```json
103
100
{
104
-
"compilerOptions": {
105
-
"module":"commonjs",
106
-
"target":"es2020",
107
-
"strict": true
108
-
},
109
-
"files": [
110
-
"script.ts"
111
-
]
101
+
"compilerOptions": {
102
+
"target": "es2020",
103
+
"module": "commonjs",
104
+
"esModuleInterop": true,
105
+
"forceConsistentCasingInFileNames": true,
106
+
"strict": true,
107
+
"skipLibCheck": true
108
+
},
109
+
"files": ["script.ts"]
112
110
}
113
111
```
114
112
115
113
The compiler options should be left as-is. The `files` directive is an array of strings with path names of all TypeScript files that make up your Node.js script or app. You can change it so that the compiler uses the right files.
116
114
117
-
Create new files in your app directory with Visual Studio Code by hovering over the name of the working directory in the left-side pane. When the **New file** icon appears, click it to create a new file. For more information on basic editing with VSC, see [Basic Editing](https://code.visualstudio.com/Docs/editor/codebasics).
115
+
Create new files in your app directory with VS Code by hovering over the name of the working directory in the left-side pane. When the **New file** icon appears, click it to create a new file. For more information on basic editing with VS Code, see [Basic Editing](https://code.visualstudio.com/Docs/editor/codebasics).
0 commit comments