[Typescript] Exclude Properties from a Type in TypeScript (Omit)
typescript in from type properties
2023-09-14 08:59:14 时间
There might be cases where you would want to create a type while excluding some of the properties from a type. Let's say you have a database query on a users
table where you are not selecting the password
field. In this case, you will not be able to assign the query results to your User
type because it is not going to have all the fields available.
In this lesson, we are going to learn how we can use TypeScript's Omit
utility type to exclude properties from a type.
type Item = { name: string; description: string; price: number; currency: string; }; type PricelessItem = Omit<Item, "price" | "currency">; const item: PricelessItem = { name: "Laptop Bag", description: "Leather bag for laptop" }; console.log(item);
相关文章
- TypeScript装饰器从入门到应用
- TypeScript学习笔记(二)—— TypeScript基础
- TypeScript 实用工具类型之 Pick 类型
- typeScript 全局库 文件声明
- 记一次vscode踩坑记录:"TypeScript 语言服务在其启动后已中止 5 次。将不会重启该服务。"
- TypeScript介绍和使用
- TypeScript系列教程《单例》
- TypeScript 编译性能优化:Project Reference
- TypeScript不学?你养我啊[2]
- 开心的档之TypeScript 变量声明
- Oracle替代in:抛弃IN,开启新的查询方式(oracle代替in)
- MySQL中实现嵌套查询的IN关键字用法(mysql嵌套查询in)
- Oracle中IN操作符的用法(oracle中in的用法)
- 方法利用SQL Server中的IN方法提升数据查询效率(sqlserver的in)
- 如何有效运用SQL Server的IN语句(sqlserver用in)
- MySQL中IN操作符的用法与注意事项(mysql中in的写法)
- MySQL中IN操作最大长度详解(mysql中in最大长度)
- MySQL中IN语句的参数化使用方法(mysql中in参数化)
- MySQL中为什么不能使用IN子查询(mysql不能in子查询)
- 利用Oracle中的IN语句优化查询效率(oracle中的in语句)
- 条件在Oracle中使用IN和OR查询条件的巧妙之处(oracle中in跟or)
- Oracle数据库中的IN关键字深度剖析(oracle中in的详解)