惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
Y
Y Combinator Blog
Jina AI
Jina AI
G
Google Developers Blog
Last Week in AI
Last Week in AI
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
The GitHub Blog
The GitHub Blog
D
Docker
量子位
罗磊的独立博客
腾讯CDC

博客园 - xgqfrms

xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs Remotion Video Maker All In One git worktree All In One Tesla 的车机使用什么技术来渲染汽车模型的? 宜家 VEVELSTAD 维维斯托床架 All In One macOS sysmond bug All In One Three.js All In One The COF of LCD Monitor All In One
xgqfrms, cnblogs, blogs
xgqfrms · 2026-09-20 · via 博客园 - xgqfrms

TypeScript type-only import All In One

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

import type { UUID } from 'crypto';

image

demos

UUID

import type { UUID } from 'crypto';

// node_modules/@types/node/crypto.d.ts
type UUID = `${string}-${string}-${string}-${string}-${string}`;

A Universally Unique IDentifier (UUID) URN Namespace

https://www.rfc-editor.org/rfc/rfc4122.txt

Nest.js

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 type
  • OmitType - constructs a type by picking all properties from an input type and then removing a particular set of keys
  • IntersectionType - combines two types into one new type (class)

https://www.npmjs.com/package/@nestjs/mapped-types

https://www.npmjs.com/package/@nestjs/swagger

refs

Introducing Mapped Types for NestJS.

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, 禁止转载 🈲️,侵权必究⚠️!