yunke-yunfly / fast-typescript-to-jsonschema

typescript-to-jsonschema generates JSON Schema files from your Typescript sources.
MIT License
33 stars 2 forks source link

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

Open sccgaochengyi opened 1 year ago

sccgaochengyi commented 1 year ago

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

不过在涉及到 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 并没有能成功取出字段,能看下是否能支持吗