指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
// ts 类型定义的两种方式,结果却不同
import type { dashboardItemNames } from "~/constants/dashboard/dasboardItemNames";
    
type Items = {
  label: string;
  name: keyof typeof dashboardItemNames;
  icon?: string | null;
  children?: Items;
}[];
  
export type UserDashboardRolesResponse = {
  label: string;
  items: Items;
}[];
  
export type ExtendedUserDashboardRolesResponse = UserDashboardRolesResponse[number] & {
  roles: number[];
}[];
  
  
  
  
import type { dashboardItemNames } from "~/constants/dashboard/dasboardItemNames";
  
type Items = {
  label: string;
  name: keyof typeof dashboardItemNames;
  icon?: string | null;
  children?: Items;
}[];
  
export type UserDashboardRolesResponse = {
  label: string;
  items: Items;
}[];
  
type ExtendedUserDashboardRole = UserDashboardRolesResponse[number] & {
  roles: number[];
};
  
export type ExtendedUserDashboardRolesResponse = ExtendedUserDashboardRole[];

使用:

const roles = ref<ExtendedUserDashboardRolesResponse>([]);
一个会报 never[], 一个不报错. 主要是ts类型检查(涉及到类型推断)的时候有问题,使用上没有问题