Skip to content

Commit dd89aa5

Browse files
author
leo
committed
update: 补充 overview/ccustom-decorators.md 未翻译部分
1 parent f299f0c commit dd89aa5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/overview/custom-decorators.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ Nest 提供了一组实用的**参数装饰器** ,可与 HTTP 路由处理程
5555
</tbody>
5656
</table>
5757

58-
Additionally, you can create your own **custom decorators**. Why is this useful?
58+
此外,你可以创建自己的**自定义装饰器**。为什么这很有用?
5959

60-
In the node.js world, it's common practice to attach properties to the **request** object. Then you manually extract them in each route handler, using code like the following:
60+
node.js 领域,通常的做法是将属性附加到 **request** 对象上。然后在每个路由处理程序中手动提取它们,使用如下代码
6161

6262
```typescript
6363
const user = req.user;
6464
```
6565

66-
In order to make your code more readable and transparent, you can create a `@User()` decorator and reuse it across all of your controllers.
66+
为了让您的代码更具可读性和透明性,您可以创建一个 `@User()` 装饰器,并在所有控制器中重复使用它。
6767

6868
```typescript title="user.decorator.ts"
6969
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
@@ -165,17 +165,17 @@ export function Auth(...roles: Role[]) {
165165
}
166166
```
167167

168-
You can then use this custom `@Auth()` decorator as follows:
168+
然后您可以按如下方式使用这个自定义的 `@Auth()` 装饰器:
169169

170170
```typescript
171171
@Get('users')
172172
@Auth('admin')
173173
findAllUsers() {}
174174
```
175175

176-
This has the effect of applying all four decorators with a single declaration.
176+
这样就可以通过声明一个装饰器从而包含四个装饰器的效果。
177177

178178
:::warning 警告
179-
The `@ApiHideProperty()` decorator from the `@nestjs/swagger` package is not composable and won't work properly with the `applyDecorators` function.
179+
`@nestjs/swagger` 包引入的 `@ApiHideProperty()` 装饰器不可组合,并且无法与 `applyDecorators` 函数一起使用。
180180
:::
181181

0 commit comments

Comments
 (0)