Skip to content

feat: inference of object properties based on a "type" infer out #53883

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
alexgwolff opened this issue Apr 18, 2023 · 2 comments
Closed
5 tasks done

feat: inference of object properties based on a "type" infer out #53883

alexgwolff opened this issue Apr 18, 2023 · 2 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@alexgwolff
Copy link

alexgwolff commented Apr 18, 2023

Suggestion

πŸ” Search Terms

out parameters, infer out, auto casting

βœ… 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

Currently, TypeScript does not support inference of object properties based on a "type" property that can contain a component type. This can be useful in cases where you want to infer the properties of a component based on its "type" property, regardless of whether it is a React component or another type of component.

πŸ“ƒ Motivating Example

type Metadata<out T extends React.ComponentType<any>> = {
  type: T;
  props: T extends React.ComponentType<infer Props> ? Props : never;
};

const metadata: Metadata = {
  type: Checkbox,
  props: {
    name: 'checkbox',
    label: 'checkbox',
    value: 'true',
  },
};

πŸ’» Use Cases

  • Better auto complete
  • infer types based props
@fatcerberus
Copy link

This feels very similar to/possibly a duplicate of #47755

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Apr 18, 2023
@RyanCavanaugh
Copy link
Member

The example section here is not well-formed. What is out doing there? What is someone who doesn't do React supposed to take away from this? What happens if the React types change and your sample doesn't work? What's the simplest version of this that anyone can understand?

@alexgwolff alexgwolff closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants