Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andyrichardson/e2740789dfd41268c98232fbb7348ccc to your computer and use it in GitHub Desktop.
Save andyrichardson/e2740789dfd41268c98232fbb7348ccc to your computer and use it in GitHub Desktop.
Quick and dirty way to force inference on a specific component property with typescript.

Quick and dirty way to force inference on a specific component property with typescript.

interface Props<T, D extends T> {
  ground: T;                  // Value of T is inferred here
  collection: D[];            // Value of T is used here but is of generic D
  function: (arg: D) => void; // And here
}

// Here we use the GroundedProps interface in our component
function MyComponent<T>(props: Props<T>) {...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment