Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Person type is too abstract #155

Open
slavafomin opened this issue Aug 7, 2019 · 5 comments
Open

Person type is too abstract #155

slavafomin opened this issue Aug 7, 2019 · 5 comments

Comments

@slavafomin
Copy link

slavafomin commented Aug 7, 2019

Hello!

Thank you for this great library!

However, the Person type is pretty abstract:

type Person =
  | {
      [k: string]: any;
    }
  | string;

It would be nice, to specify the fields, like name, email, website etc.

Here's my implementation from our private project:

type Person = (string | {
  name: string;
  email?: string;
  url?: string;
})

Thanks!

@ffflorian
Copy link
Owner

Hi @slavafomin, you are probably talking about the types for package, right?

I didn't write them manually, but they are generated from SchemaStore's package.json. So you should probably open an issue at schemastore.

Maybe you can team up with @G-Rath, who also worked on this schema before (see #88).

@G-Rath
Copy link

G-Rath commented Aug 11, 2019

@ffflorian the definition for Person is already in the schema:

    "person": {
      "description": "A person who has been involved in creating or maintaining this package",
      "type": ["object", "string"],
      "required": ["name"],
      "properties": {
        "name": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "email": {
          "type": "string",
          "format": "email"
        }
      }
    },

https://github.com/SchemaStore/schemastore/blob/fa677f8217cc058a93ba4472ff79a98b8968dcde/src/schemas/json/package.json#L5-L22

I can't entirely remember where we left things, but currently I think it might be the generator hasn't been run recently, or it's not just creating a typing for it for some reason?

Either way, the schema has the information, meaning the problem is in your domain 😉

I'm happy to help, but am right now pretty busy converting eslint-plugin-jest to TypeScript (hence me gently pushing the ball back into your court, rather then investigating myself).

I've still actually got to finish off implementing the flag for generating "strict" typings for you as well 😬 (it's done, but I need to write tests & make a PR).


Actually, I have a hunch the problem is b/c it's type: [object, string]

Confirmed: it's b/c it's of type: [object, string]. I'll have a look at the generator repo, but you'd be doing me a huge favor if you'd handle champaining this for me.

If you get me an issue, I'm happy to action it w/ a PR, but don't have the time to do handle the whole "find existing issue, create if one doesn't exist already" stuff - even if you just make an issue & tag me in it over on json-schema-to-typescript, that'd be good 🙂


It's b/c of this bug

@ffflorian
Copy link
Owner

@G-Rath thank you very much for the investigation! Let's hope the bug gets resolved soon.

@ffflorian
Copy link
Owner

@G-Rath in the meantime, the bug was closed as completed 🥳

Today, I re-generated a lot of schemas and the package schema got changed a lot.

@slavafomin the new Person type looks like this now:

/**
 * A person who has been involved in creating or maintaining this package.
 */
export type Person = {
  name: string;
  url?: string;
  email?: string;
  [k: string]: unknown;
} & Person1;
export type Person1 =
  | {
      name: string;
      url?: string;
      email?: string;
      [k: string]: unknown;
    }
  | string;

You can try it out by using @schemastore/package with version 0.0.7.

@G-Rath
Copy link

G-Rath commented Feb 24, 2023

@ffflorian awesome, though the types are invalid for another reason - I've opened #680 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants