Skip to content

另一种 Pick 的使用方式,不支持 #28

@sccgaochengyi

Description

@sccgaochengyi

感谢作者的辛勤劳动,这个包解析的效果非常好。

不过在涉及到 Pick Omit 时,估计是因为我使用方式与 demo 中的不同,所以没解析出来。

export type CompetitorCompanyDBEntry = {
  name?: string;
  creatorId: number;
};

export const competitorCompanyPickFields = Object.freeze(['creatorId'] as const);

export type CompetitorCompany = Pick<
  CompetitorCompanyDBEntry,
  (typeof competitorCompanyPickFields)[number]
> & {
  name: string;
};

解析出来的效果是

"CompetitorCompany": {
      "allOf": [
        {
          "$ref": "#Pick",
          "items": {
            "$ref": "#CompetitorCompanyDBEntry"
          }
        },
        {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
          },
          "required": [
            "name"
          ]
        }
     ]
}

我估计是因为使用 (typeof competitorCompanyPickFields)[number] 的方式,导致 Pick 并没有能成功取出字段,能看下是否能支持吗

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions