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

Shorthand for types/interfaces with properties of same type #30149

Closed
knomdlo opened this issue Feb 28, 2019 · 1 comment
Closed

Shorthand for types/interfaces with properties of same type #30149

knomdlo opened this issue Feb 28, 2019 · 1 comment
Labels
Question An issue which isn't directly actionable in code

Comments

@knomdlo
Copy link

knomdlo commented Feb 28, 2019

Search Terms

Interface shorthand, sugar syntax, interfaces of same type, types of same type

Suggestion

Can a shorthand be added to create interfaces/types that have all keys of same type.

Use Cases

Reduce the no of lines & also help in readability.

Examples

export interface AllStrings { prop1: string; prop2: string; }

to something like

export interface AllStrings<type: string> { prop1,prop2; }

Checklist

My suggestion meets these guidelines:

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

What about:

type AllStrings = Record<"prop1" | "prop2", string>

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants