Skip to content

Commit 7afb1c7

Browse files
2 parents 16451f1 + 11edab0 commit 7afb1c7

File tree

6 files changed

+185
-198
lines changed

6 files changed

+185
-198
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.18.2
1+
12.18.3

content/enterprise.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ With official support, get expert help directly from the NestJS core team. We ta
2121
</p>
2222
</div>
2323
<div class="thumbnail p-l-30">
24-
<img src="/assets/enterprise/help.svg">
24+
<img src="/assets/enterprise/help.svg" />
2525
</div>
2626
</div>
2727

2828
<div class="row">
2929
<div class="thumbnail p-r-30">
30-
<img src="/assets/enterprise/contact.svg">
30+
<img src="/assets/enterprise/contact.svg" />
3131
</div>
3232
<div class="content">
3333
<h4>NestJS Best Practices</h4>

content/fundamentals/unit-testing.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,30 +256,31 @@ Each of the override method types, in turn, returns the `TestingModule` instance
256256
The compiled module has several useful methods, as described in the following table:
257257

258258
<table>
259-
<tr>
260-
<td>
261-
<code>createNestApplication()</code>
262-
</td>
263-
<td>
264-
Creates and returns a Nest application (<code>INestApplication</code> instance) based on the given module.
265-
Note that you must manually initialize the application using the <code>init()</code> method.
266-
</td>
267-
</tr>
268-
<tr>
269-
<td>
270-
<code>createNestMicroservice()</code>
271-
</td>
272-
<td>
273-
Creates and returns a Nest microservice (<code>INestMicroservice</code> instance) based on the given module.
274-
</td>
275-
</tr>
276-
<tr>
259+
<tr>
260+
<td>
261+
<code>createNestApplication()</code>
262+
</td>
263+
<td>
264+
Creates and returns a Nest application (<code>INestApplication</code> instance) based on the given module.
265+
Note that you must manually initialize the application using the <code>init()</code> method.
266+
</td>
267+
</tr>
268+
<tr>
269+
<td>
270+
<code>createNestMicroservice()</code>
271+
</td>
272+
<td>
273+
Creates and returns a Nest microservice (<code>INestMicroservice</code> instance) based on the given module.
274+
</td>
275+
</tr>
276+
<tr>
277277
<td>
278278
<code>get()</code>
279279
</td>
280280
<td>
281281
Retrieves a static instance of a controller or provider (including guards, filters, etc.) available in the application context. Inherited from the <a href="/fundamentals/module-ref">module reference</a> class.
282282
</td>
283+
</tr>
283284
<tr>
284285
<td>
285286
<code>resolve()</code>

content/techniques/configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ As shown above, use the `configService.get()` method to get a simple environment
153153
const dbHost = this.configService.get<string>('database.host', 'localhost');
154154
```
155155

156+
`ConfigService` has an optional generic (type argument) to help prevent accessing a config property that does not exist. Use it as shown below:
157+
158+
```typescript
159+
interface EnvironmentVariables {
160+
PORT: number;
161+
TIMEOUT: string;
162+
}
163+
164+
// somewhere in the code
165+
constructor(private configService: ConfigService<EnvironmentVariables>) {
166+
// this is valid
167+
const port = this.configService.get<number>('PORT');
168+
169+
// this is invalid as URL is not a property on the EnvironmentVariables interface
170+
const url = this.configService.get<string>('URL');
171+
}
172+
```
173+
174+
> warning **Notice** If you have nested properties in your config, like in the `database.host` example above, the interface must have a matching `'database.host': string;` property. Otherwise a TypeScript error will be thrown.
175+
156176
#### Configuration namespaces
157177

158178
The `ConfigModule` allows you to define and load multiple custom configuration files, as shown in <a href="techniques/configuration#custom-configuration-files">Custom configuration files</a> above. You can manage complex configuration object hierarchies with nested configuration objects as shown in that section. Alternatively, you can return a "namespaced" configuration object with the `registerAs()` function as follows:

0 commit comments

Comments
 (0)