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

Utility Type - PartialRecord #43918

Closed
5 tasks done
tylersayshi opened this issue May 1, 2021 · 1 comment
Closed
5 tasks done

Utility Type - PartialRecord #43918

tylersayshi opened this issue May 1, 2021 · 1 comment

Comments

@tylersayshi
Copy link

tylersayshi commented May 1, 2021

Suggestion

I believe it would be useful to have a type PartialRecord. This SO Post has had 13k+ views so I believe this is a commonly desired type.

πŸ” Search Terms

PartialRecord, Partial Record

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

New Utility Type: PartialRecord

type PartialRecord<K extends keyof any, T> =  Partial<Record<K, T>>;

or

type PartialRecord<K extends keyof any, T> = {
  [P in K]?: T;
};

(from SO Post linked above)

πŸ“ƒ Motivating Example

This improves the basic support of Typescripts Utility types by adding support for a commonly desired pattern.

πŸ’» Use Cases

I want to use this for conveniently defining Partial Record types without needing to maintain and import one in each project I need this pattern.

Current workaround is to define your own, but this is obviously not ideal.

@MartinJohns
Copy link
Contributor

See #39522 (comment):

We've opted to not include utility type aliases in the lib unless they're required for declaration emit purposes.

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

2 participants