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

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LINUX DO - 最新话题
Recorded Future
Recorded Future
月光博客
月光博客
博客园 - 【当耐特】
博客园 - 叶小钗
宝玉的分享
宝玉的分享
量子位
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Vercel News
Vercel News
L
LangChain Blog
B
Blog
Y
Y Combinator Blog
爱范儿
爱范儿
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - Franky
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
Scott Helme
Scott Helme
I
Intezer
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
N
News and Events Feed by Topic
大猫的无限游戏
大猫的无限游戏
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security Affairs
Cyberwarzone
Cyberwarzone
PCI Perspectives
PCI Perspectives
小众软件
小众软件
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
S
Securelist
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
The Last Watchdog
The Last Watchdog

时间的朋友

Windows 命令行密码重置 Anaconda安装 Konvajs Shape加载自定义图片 sshpass 使用 why-is-node-running webgl笔记 SharedArrayBuffer is not defined blender 常用快捷键 vue -- v3.4commit提交记录2 vue2 升级vue3报错问题整理 着色器 expressjs 源码 hyper-V arch linux 网络配置 element input数字格式化 three 拼接货架 WebAudio笔记 Windows nginx重启bat脚本 vue -- v3.4commit提交记录 URI malformed vue3 -- Class 对象在组件中使用范例 | 时间的朋友 ruby 安装和升级 element-plus 老版本cascader使用卡死问题 vue3 内置Transition组件 前端memo的实现 Vue -- vue-class-component源码 linux 优化脚本 typescript 装饰器 microbundle 源码 WSL2问题解决WslRegisterDistribution failed with error: 0x800701bc vue -- vue3利用createVNode函数,建立命令式调用组件 SSH connection failed: connect ECONNREFUSED 请求中获取浏览器推荐语言 flutter 生命周期 双向链表 堆和栈 EventSource 单向链表 简易的事件监听EventBus fork的仓库更新分支 forwardRef 定义的组件添加静态属性 js 获取滚动元素 canvas requestAnimationFrame画一个clock mousedown event中保持input的focus状态 vue -- @vue/compiler-core整体逻辑 IOS端h5 fixed滚动问题 vue -- compile结果代码解读 vue -- transformElement源码 Vue -- 内置指令源码 vue3 -- @vue/compiler-sfc compileScript源码 浏览器工作原理 对比2个版本号的方法 vite 向entry html中注入代码 小程序 -- 内部使用webview绑定微信公众号openId github coding同步action 小程序 -- 微信外部浏览器或者链接打开方式整理 MSE -- MediaSource 的前端使用 rollup 打包vue2组件 常用工具函数整理 Benchmark.js 使用 import-html-entry js沙箱实现源码 import-html-entry 笔记 axios core源码 国内开源镜像网站 nuxt -- docker-compose进行部署 vue -- provide和inject原理 vue -- hoistStatic原理 jenkins 配置模板代码 vue -- compileTemplate原理 小程序开发问题整理 webpack-dev-server proxy代理模块 vite 代理中更改请求头问题 Async.js flutter 问题整理 比较两个数组的不同项 ms源码解析 浏览器同源策略 前端缓存笔记 webpack5 schema-utils tsc 和 babel 编译typescript区别 typescript 学习笔记 esbuild api整理 Webpack Chain 源码 deepmerge库源码解读 Vue 自定义指令的执行机制 linux 问题整理 webpack5学习笔记 elementui form多表单验证 Webpack5 -- Assest Module vue -- 实现MenuTree组件 Vue -- VFor的编译处理 vue -- 使用中问题整理 算法基础知识 浏览器环境检测函数整理 yarn 问题搜集 c++笔记 webpack 模块加载原理 webpack 模块加载原理(二) Zero Width Characters slate.js API整理 slate.js 富文本编辑器
typescript 注解解读1
2024-08-19 · via 时间的朋友

源注解代码 🔗

1
2
3
4
5
6
7
8
9
{ 
    readonly [K in keyof Defaults as K extends keyof T
    	? K
    	: never]-?: K extends keyof T
    	? Defaults[K] extends undefined
      	? IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>
      	: NotUndefined<T[K]>
    	: never
}

解读 🔗

  1. 索引签名和可选性: readonly [K in keyof Defaults as ...] -?:
    • readonly: 表示生成的属性是只读的。
    • [K in keyof Defaults]: 定义了一个索引签名,遍历 Defaults 的所有键。
    • as ...: 这里是一个类型条件,用来过滤键。
    • -?: 可以移除或保留属性的可选项标记 (?)。在这个场景中,由于 -? 在条件之后,所以它不会立即应用。
  2. 类型条件:
    • K extends keyof T ? K : never: 这个条件确保只有那些同时存在于 TDefaults 中的键才会被包含进来。
  3. 内部类型条件:
    • K extends keyof T ? ... : never: 再次确认 KT 的键。
    • Defaults[K] extends undefined ? ... : NotUndefined<T[K]>: 检查Defaults[K]是否为undefined
      • 如果是undefined:
        • 使用 IfAny<Defaults[K], NotUndefined<T[K]>, T[K]>。这里 IfAny 是一个自定义类型,用于处理当 Defaults[K] 为任何类型时的情况。如果 Defaults[K] 为任意类型(即 any),则结果类型是 NotUndefined<T[K]>;否则,结果类型是 T[K]
      • 如果不是undefined:
        • 直接使用 NotUndefined<T[K]>,即去除 T[K]undefined 值。
  4. 辅助类型:
    • IfAny<T, U, V>: 当 Tany 时选择 U 类型,否则选择 V 类型。
    • NotUndefined<T>: 去除类型 T 中的 undefined

总结 🔗

最终生成的类型会根据 Defaults 中的值来决定 T 的属性类型:

  • 如果 Defaults[K]undefined,那么 T[K] 的类型会保持不变(除非 T[K] 本身就是 undefined,此时它会被替换为非 undefined 的类型)。
  • 如果 Defaults[K] 不是 undefined,那么 T[K] 的类型将被限制为非 undefined

注意:这里的 IfAnyNotUndefined 需要额外定义。