[!Typescript] Tips: Access deeper parts of objects and arrays
typescript and of access Tips Objects Arrays
2023-09-14 08:59:11 时间
Accessing object values and array members is MUCH more powerful in the type world than it is in the runtime world.
Passing a union... RETURNS a union!
interface ColorVariants {
primary: "blue";
secondary: "red";
tertiary: "green";
}
type PrimaryColor = ColorVariants["primary"]; // "blue"
type NonPrimaryColor = ColorVariants["secondary" | "tertiary"]; // "red" | "green"
type EveryColor = ColorVariants[keyof ColorVariants]; // "blue" | "red" | "green"
type Letters = ["a", "b", "c"];
type AOrB = Letters[0 | 1]; // "a" | "b"
type Letter = Letters[number]; // "a" | "b" | "c"
interface UserRoleConig {
user: ["view", "create", "update"];
superAdmin: ["view", "create", "update", "delete"];
}
type Role = UserRoleConig[keyof UserRoleConig][number] // "view" | "create" | "update" | "delete"
相关文章
- Typescript教程_安装typescript
- 前端 QA 工具链指南 - husky,commitlint,commitizen,eslint,typescript,express
- 【说站】微软官方发布TypeScript 4.4版本
- TypeScript 编译性能优化:Project Reference
- 解决 Typescript 文件被识别为视频的问题
- Vue 3 + Typescript + Vite 基于jsplumb流程设计和流程流转
- Laravel + Vue 3(Vite、TypeScript)SPA 设置
- TypeScript 类型体操:合并映射类型的处理结果为联合类型
- 开发者数量2025年预计破亿,TypeScript受欢迎度飙升:GitHub最新年度报告
- TypeScript入门
- 【TypeScript】条件语句
- TypeScript遭库开发者嫌弃:类型简直是万恶之源
- 开心档之TypeScript 变量声明
- Vue2+TypeScript+CompositionAPI实践
- 深入浅出:MySQL中AND和OR运算符使用方法(mysql中and和or)
- Oracle数据库中的AND查询(oracle and查询)
- MySQL中AND的使用方法解析(mysql中and的用法)
- MySQL中AND的使用方法及含义解析(mysql中and的含义)