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

TypedPropertyDescriptorMap<T> #40137

Open
5 tasks done
stuft2 opened this issue Aug 19, 2020 · 0 comments
Open
5 tasks done

TypedPropertyDescriptorMap<T> #40137

stuft2 opened this issue Aug 19, 2020 · 0 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@stuft2
Copy link

stuft2 commented Aug 19, 2020

Search Terms

TypedPropertyDescriptor
TypedPropertyDescriptorMap
Typed Property Descriptor Map

Suggestion

Include TypedPropertyDescriptorMap<T>, the typed version of PropertyDescriptorMap. The following type should do the trick:

type TypedPropertyDescriptorMap<T> = {
  [P in keyof T]: TypedPropertyDescriptor<T[P]>
}

This would require a change to the Object.defineProperties type definition since it only accepts a PropertyDescriptorMap type, an indexed type. Passing in an object with a type of TypedPropertyDescriptorMap<T> results in the error: Index signature is missing in type 'TypedPropertyDescriptorMap<T>'. There's a related issue on this topic (#15300).

Use Cases

It's a headache to have to define a type like the following when I already have defined the final object type:

// Final object looks like
interface MyProps {
  prop1: string
  prop2: (params: Record<string, string>) => Promise<void>
}

// My custom TypedPropertyDescriptor map
interface MyPropDescriptors {
  prop1: TypedPropertyDescriptor<MyProps['prop1']>
  prop2: TypedPropertyDescriptor<MyProps['prop2']>
  ...
}

Examples

// Final object looks like
interface MyProps {
  prop1: string
  prop2: (params: Record<string, string>) => Promise<void>
}

// My custom TypedPropertyDescriptor map
type MyPropDescriptors = TypedPropertyDescriptorMap<MyProps>

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants