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

Separate the standard PackageJson types into it's own type #122

Closed
barak007 opened this issue Aug 18, 2020 · 4 comments · Fixed by #128
Closed

Separate the standard PackageJson types into it's own type #122

barak007 opened this issue Aug 18, 2020 · 4 comments · Fixed by #128

Comments

@barak007
Copy link
Contributor

barak007 commented Aug 18, 2020

It will be nice to separate the standard part from the PackageJson type into it's own type let's say PackageJson.PackageJsonStandard.
This will allow to use keyof PackageJson.PackageJsonStandard and get the actual keys.
Right now since there is & {[key: string]: unknown;} at the end of the type the keyof operator is not very useful it returns string | number.

My use-case is that I want to write a function to copy standard values from one package.json to anther and I want it to be typesafe.

Example:

function copyCommonPackageValues(
  target: PackageJson,
  origin: PackageJson,
  // This is not safe right now I need something like keyof PackageJson.PackageJsonStandard
  keys: Array<keyof PackageJson>
) {
  for (const key of keys) {
    const value = origin[key];
    if (value) {
      target[key] = value;
    }
  }
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

I'm actually not sure why we have & {[key: string]: unknown;} there. Unless you see a good reason it's there, maybe we could just remove it? People that need it, could easily add that themselves.

@papb
Copy link
Contributor

papb commented Aug 20, 2020

I agree, I wouldn't mind seeing this & {[key: string]: unknown;} removed as well.

@barak007
Copy link
Contributor Author

Removing it will probably will be a major change for some people. If you have no problem with that I'm in. if not I can open a PR with the proposed change.

@sindresorhus
Copy link
Owner

Yes, PR welcome.

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

Successfully merging a pull request may close this issue.

3 participants