Skip to content

ObjectTypes Utility Function #55850

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

Closed
5 tasks done
lucasdomanico opened this issue Sep 24, 2023 · 3 comments
Closed
5 tasks done

ObjectTypes Utility Function #55850

lucasdomanico opened this issue Sep 24, 2023 · 3 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@lucasdomanico
Copy link

πŸ” Search Terms

Hello, I would want to create a tuple with the given object types.
For example

let o:{ i:number, j:string } = { i:1, j:'a' }
type X = ObjectTypes<o>
// X is [number, string]

βœ… Viability Checklist

  • 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 our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

⭐ Suggestion

ObjectTypes utility function

πŸ“ƒ Motivating Example

type X = {
    i: number
    j: string
}
let f = (...a:ObjectTypes<X>) => ...

πŸ’» Use Cases

  1. What do you want to use this for?
    Avoid repeating too much code (identifiers and types)

  2. What shortcomings exist with current approaches?
    Repeating too much code (identifiers and types)

  3. What workarounds are you using in the meantime?
    Repeating too much code (identifiers and types)

@xiBread
Copy link

xiBread commented Sep 24, 2023

#39522 (comment)

@fatcerberus
Copy link

Chalk up another vote for #55746

@IllusionMH
Copy link
Contributor

I believe there is no guarantees about properties (in this case related values types) order, so you can't get tuple out object with fixed order.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants