Created
May 27, 2021 22:18
-
-
Save chaance/2ed2d006976023b47b00e000baca73cd to your computer and use it in GitHub Desktop.
Inferred link props with TS template literal types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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