












import type是 TypeScript 的 type-only import 写法, 表示“只导入类型 UUID,不导入运行时值”。
import type { UUID } from 'crypto';

UUID
import type { UUID } from 'crypto';
// node_modules/@types/node/crypto.d.ts
type UUID = `${string}-${string}-${string}-${string}-${string}`;
UUID) URN Namespacehttps://www.rfc-editor.org/rfc/rfc4122.txt
PartialType
# validation
$ npm install class-validator class-transformer
# ?
$ npm i @nestjs/mapped-types
$ npm i @nestjs/swagger
PartialType - returns a type (class) with all the properties of the input type set to optional (requirement: at least 1 validation decorator applied to each property)PickType - constructs a new type (class) by picking a set of properties from an input typeOmitType - constructs a type by picking all properties from an input type and then removing a particular set of keysIntersectionType - combines two types into one new type (class)https://www.npmjs.com/package/@nestjs/mapped-types
https://www.npmjs.com/package/@nestjs/swagger
Introducing
Mapped TypesforNestJS.
Mapped Types are supported by both REST (@nestjs/swagger) and GraphQL (@nestjs/graphql) applications.
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, MinLength } from 'class-validator';
export class CreateUserDto {
@IsEmail()
@ApiProperty()
email: string;
@MinLength(10)
@ApiProperty()
password: string;
}
import { CreateUserDto } from './create.profile.dto';
// RESTful API ✅ swagger
import { PartialType } from '@nestjs/swagger';
export class UpdateUserDto extends PartialType(CreateUserDto) {
// 复用
}
import { InputType, Field } from '@nestjs/graphql';
@InputType()
class CreateUserInput {
@Field()
email: string;
@Field()
password: string;
}
// GraphQL API ✅ graphql
import { InputType } from '@nestjs/graphql';
import { PartialType } from '@nestjs/graphql';
@InputType()
export class UpdateUserInput extends PartialType(CreateUserInput) {}
https://trilon.io/blog/introducing-mapped-types-for-nestjs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。