Skip to content

Instantly share code, notes, and snippets.

@chaance
Created May 27, 2021 22:18
Show Gist options
  • Save chaance/2ed2d006976023b47b00e000baca73cd to your computer and use it in GitHub Desktop.
Save chaance/2ed2d006976023b47b00e000baca73cd to your computer and use it in GitHub Desktop.
Inferred link props with TS template literal types
type LinkProps<T extends { href: any }> = T extends { href: infer U }
// If our `href` prop starts with a given substring, we might
// determine that we have an external link and filter internal
// routing-related props. This could just as easily work in reverse!
? U extends `https://${string}` | `http://${string}`
? ExternalLinkProps
: InternalLinkProps
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment