请问一下: 我们在很多地方有看到 安装 "@types/xxx" 之类的信息。 请教两个问题: 1、@types/xxx 的作用是用于进行多个项目共用定义的type, interface对吗? 2、请问哪里有好的教程用于学习如何封装"@types/xxx" 然后进行打包上传呢?
https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241010/f71e1f27a9a551ec001ff45d3fbf7e65.png 一直认为implements只能实现interface,今天看到某个开源项目,prisma+nest,通过prisma的类型来定义entity,发现type也能实现,type不是仅仅是一个类型别名吗? ! https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241010/f71e1f27a9a551ec001ff45d3fbf7e65.png
如何给组件的props设置默认值? interface CodeModCreatorProps { grpLvlColor: string[] } function CodeModCreator({ grpLvlColor: ['red', 'green'] // 这样传输会报错 }: CodeModCreatorProps) { return ( ); } export default CodeModCreator; "QQ_1725198806049.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240914/74b9f11774becd98483d72099f0f3443.png)
vue模板类型缩小 这是我的类型文件,但是有个问题,为什么ListItem下的controlListType类型缩小不了,一直是unknow,就很奇怪"image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240925/367a63f36666e6510f873a55a19049d8.png),用模板也是这样,我不知道是不是我想法有问题还是怎么样,或者说我需要怎么改进 declare interface ControlType { input: { config: { placeholder?: string; rows?: number; maxLength?: number; }; check?: { type: string; message: string; }; }; select: { config: { placeholder?: string; options?: Array; mode?: string; lableKey: string; valueKey: string; }; check?: { type: string; message: string; }; }; radio: { config: { options?: Array; name: string; }; check?: { type: string; message: string; }; }; date: { config: {}; check: {}; }; dateRange: {}; } declare type ControlListType = { type: K; config: ControlType[K]["config"]; check?: ControlType[K]["check"]; }; declare type displayStyleType = { backgroundColor?: string; color?: string; border?: string; }; type width = 50 | 100; declare interface ListItem { id: string | number; // 字段id filedName: string; // 字段名称 value?: string | (() => string) | ""; // 显示字段,如果是对象结构,展示需要层级,或者函数,函数用于处理多层级数据或者数组或者格式化数据 // value返回值提供样式修改,如果value是个函数,displayStyle 失效,需要在此返回值中配置样式可以 直接返回dom结构,对于dom的class或者id,提供额外的style插入。如果复杂的话后续考虑返回jsx,对jsx进行编译 name: string; // 展示名称 displayStyle?: displayStyleType; // 列表显示样式,默认显示文本或者提供配置,背景色和文本颜色,只有value是 string 的时候生效 controlListType: ControlListType; // 控件列表,提供配置、校验、等一些特有控件的私有配置 ,这个只提供一些常规配置,有其他需求的通过 code 编码, width?: width; // 展示列表宽度,默认一半 deploy: { isSearch: boolean; // 是否查询字段 isAdd: boolean; // 是否新增 isEdit: boolean; // 是否编辑 }; }
看到一个interface的声明,非常复杂: interface PromiseLike { /** * Attaches callbacks for the resolution and/or rejection of the Promise. * @param onfulfilled The callback to execute when the Promise is resolved. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; } 1、这个很难看懂,请问一下,应该如何学习这个定义呢? 是否可以拆分一点一点地学到它的含义? 2、需要带着什么样的思路才能去看懂,从想要定义它的目的去阅读吗?