From 64346fccc358ceb02ec56439728bd46f37da4b8c Mon Sep 17 00:00:00 2001 From: ThierryRakotomanana Date: Mon, 23 Mar 2026 21:26:14 +0300 Subject: [PATCH 1/2] fix(typescript-guide): improve grammar and set right command --- src/content/guides/typescript.mdx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/content/guides/typescript.mdx b/src/content/guides/typescript.mdx index 317baf1d3f7a..b8fdb65c7d85 100644 --- a/src/content/guides/typescript.mdx +++ b/src/content/guides/typescript.mdx @@ -25,7 +25,9 @@ First install the TypeScript compiler and loader by running: npm install --save-dev typescript ts-loader ``` -Now we'll modify the directory structure & the configuration files: +Now we'll modify the directory structure & the configuration files, we need to swap our JavaScript files over to TypeScript. Rename the core files by changing their extensions from .js to .ts as shown below: +`.src/index.js` to `./src/index.ts` +and `webpack.config.js` to `webpack.config.ts` **project** @@ -34,12 +36,13 @@ Now we'll modify the directory structure & the configuration files: ├── package.json ├── package-lock.json + ├── tsconfig.json - ├── webpack.config.js +- ├── webpack.config.js ++ ├── webpack.config.ts ├── /dist │ ├── bundle.js │ └── index.html ├── /src - │ ├── index.js +- │ ├── index.js + │ └── index.ts └── /node_modules ``` @@ -114,7 +117,14 @@ export default config; This will direct webpack to _enter_ through `./index.ts`, _load_ all `.ts` and `.tsx` files through the `ts-loader`, and _output_ a `bundle.js` file in our current directory. -Now lets change the import of `lodash` in our `./index.ts` due to the fact that there is no default export present in `lodash` definitions. +Next, we need to adjust how we import `lodash` in our `./index.ts`. Since the lodash definitions don't include a default export, we'll need to update our import statement. +First, make sure to install the [TypeScript definitions](#using-third-party-libraries): + +```bash +npm install --save-dev @types/lodash +``` + +Then, update your import at the top of the file: **./index.ts** @@ -142,7 +152,7 @@ There are 3 ways to use TypeScript in `webpack.config.ts`: 1. **Using webpack with built-in Node.js type stripping feature (recommended):** ```bash - webpack -c ./webpack.config.ts + npx webpack -c ./webpack.config.ts ``` Will attempt to load the configuration using Node.js's built-in [type-stripping](https://nodejs.org/api/typescript.html#type-stripping), and then attempt to load the configuration file using `interpret` and `rechoir` (in this case you need to install `tsx` or `ts-node` or other tools). @@ -318,7 +328,7 @@ To enable the types for the whole project, add `webpack/module` to `compilerOpti When installing third party libraries from npm, it is important to remember to install the typing definition for that library. -For example, if we want to install lodash we can run the following command to get the typings for it: +For example, if we want to use lodash, we should run the following command to install its type definitions: ```bash npm install --save-dev @types/lodash From 4cbf5b484fe3379fc7e1a7fb3e53f24881cab7d5 Mon Sep 17 00:00:00 2001 From: ThierryRakotomanana Date: Mon, 23 Mar 2026 22:14:30 +0300 Subject: [PATCH 2/2] refactor(guides): remove unecessary paragraph & command --- src/content/guides/typescript.mdx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/content/guides/typescript.mdx b/src/content/guides/typescript.mdx index b8fdb65c7d85..18326ae1a2ab 100644 --- a/src/content/guides/typescript.mdx +++ b/src/content/guides/typescript.mdx @@ -25,9 +25,7 @@ First install the TypeScript compiler and loader by running: npm install --save-dev typescript ts-loader ``` -Now we'll modify the directory structure & the configuration files, we need to swap our JavaScript files over to TypeScript. Rename the core files by changing their extensions from .js to .ts as shown below: -`.src/index.js` to `./src/index.ts` -and `webpack.config.js` to `webpack.config.ts` +Now we'll modify the directory structure & the configuration files: **project** @@ -152,7 +150,7 @@ There are 3 ways to use TypeScript in `webpack.config.ts`: 1. **Using webpack with built-in Node.js type stripping feature (recommended):** ```bash - npx webpack -c ./webpack.config.ts + webpack -c ./webpack.config.ts ``` Will attempt to load the configuration using Node.js's built-in [type-stripping](https://nodejs.org/api/typescript.html#type-stripping), and then attempt to load the configuration file using `interpret` and `rechoir` (in this case you need to install `tsx` or `ts-node` or other tools).