首页
笔记
趣玩
其他
文章搜索...
JavaScript
TypeScript
React
Npm
Git
Css
小程序
面试题
章节
All
基础
进阶
组件使用
进阶
箭头函数写泛型
// tsx 中需要加多个 , 或者 extends,否则会识别成 react 的标签 const fn = <T>(p: T): T => { return p; }; const fn2 =
lhh
|
07/31/2024 14:19
进阶
读取对象数组中的对象类型
type Person = { name: string; age: number; schools: { id: string }[] }; type PersonSchool = Person["
lhh
|
07/31/2024 14:19
进阶
读取对象的 key 作为 type
const person = { name: "lhh", age: "18" }; type PersonKey = keyof typeof person; type Person = { [ke
lhh
|
07/31/2024 14:19
进阶
将类型的所有可选属性转为必选
/** 将类型的所有可选属性(包括嵌套的,同时移除null)都转化为必选 */ type DeepRequired<T> = { [P in keyof T]-?: T[P] extends ob
lhh
|
07/31/2024 14:18
进阶
将指定 key 变为必选
type RequireKey<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: T[P] }; // type RequireKey2<T, K
lhh
|
07/31/2024 14:18
进阶
将指定 key 变为可选
type WithPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; type Person = { id: str
lhh
|
07/31/2024 14:18
博主很懒,就这么多啦~~