[Typescript] The naked type
typescript The type
2023-09-14 08:59:11 时间
So what is a nake type?
Example:
type UnionToIntersection<T> =
(T extends any ? (x: T) => any : never) //...
We check T
in a sub-type condition,
T extends any ?...
And T is not wrapping with anything:
type Naked<T> = T extends ... // naked!
type NotNaked<T> = { o: T } extends ... // not naked!
Feature of The naked type
If T
is a union type, Typescript run each item of the T
against the condition.
So with a naked type, a conditional of union types becomes a union of conditional types, For example:
type WrapNaked<T> =
T extends any ? { o: T } : never;
type Foo = WrapNaked<string | number | boolean>
// equals to
type Foo = WrapNaked<string> | WrapNaked<number> | WrapNaked<boolean>
// equals to
type Foo =
string extends any ? { o: string } : never |
number extends any ? { o: number } : never |
boolean extends any ? { o: boolean } : never
type Foo =
{ o: string } | { o: number } | { o: boolean }
As compared to the non-naked version:
type WrapNaked<T> =
{ o: T } extends any ? { o: T } : never
type Foo = WrapNaked<string | number | boolean>
// A non Naked type, so this equals to
type Foo = { o: string | number | boolean } extends any ? { o: string | number | boolean } : never
type Foo = { o: string | number | boolean }
相关文章
- 计算时间差工具类(TypeScript/JavaScript)
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.
- The method assertEquals(double, double) from the type Assert is deprecated
- typescript web_typescript文档
- 前端 QA 工具链指南 - husky,commitlint,commitizen,eslint,typescript,express
- TypeScript 实用工具类型之 Omit 类型
- 【踩坑实录】-java.sql.SQLException: The MySQL server is running with the LOCK_WRITE_GROWTH option so it ca
- 【React】1427- 如何使用 TypeScript 开发 React 函数式组件?
- Mysql 1290 - The MySQL server is running with the --secure-file-priv option
- TypeScript,我从不喜欢到沉迷
- TypeScript泛型应用
- Laravel + Vue 3(Vite、TypeScript)SPA 设置
- 开心的档之TypeScript 变量声明
- TypeScript 5.0 现已发布:全新的装饰器,速度、内存和包大小优化
- 【错误记录】Flutter 编译报错 ( The parameter ‘‘ can‘t have a value of ‘null‘ because of its type, but the im )
- 调查:React 仍然是使用最广泛的前端框架,TypeScript 是优先选项
- Node.js脚手架开发完全指南「TypeScript版」
- ORA-01378: The logical block size (string) of file string is not compatible with the disk sector size (media sector size is string and host sector size is string) ORACLE 报错 故障修复 远程处理
- ORA-22900: the SELECT list item of THE subquery is not a collection type ORACLE 报错 故障修复 远程处理
- ORA-38407: The ADT associated with the attribute set already exists. ORACLE 报错 故障修复 远程处理
- ORA-41104: The database: string is the Cluster Director. ORACLE 报错 故障修复 远程处理
- ORA-48408: The incident number exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-53035: The rows for the mapping document (string) do not exist. ORACLE 报错 故障修复 远程处理
- Exploring the Depths of Linux: The Power of the l Command(linux-l)
- Exploring the Power of Linux: The Versatility and Potential of Aud Files(linux系统aud文件)
- Discover the Versatility of Tilda Linux: The Perfect Operating System for Tech Enthusiasts.(tildalinux)
- Unveiling the Evolution of Linux: The Journey of the 0.11 Version(linux0.11)