Last active
February 13, 2018 20:36
-
-
Save DethAriel/701830b6e0a99843bd19bcfbb18197c1 to your computer and use it in GitHub Desktop.
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
// This Gist is created for the https://stackoverflow.com/questions/48774804/ StackOverflow question | |
interface Icon { src: string; } | |
interface IconSet { | |
[iconName: string]: Icon; | |
} | |
type UiBuilder = <P, S extends IconSet>(iconRegistry: S) => { | |
withIcon<K extends keyof S>(iconName: K): null, | |
}; | |
const listIcons: IconSet = { | |
sort: { src: 'sort.svg' }, // Expected to be OK | |
email: { source: 'email.svg' }, // Expected to ERR | |
}; | |
const profileIcons: IconSet = { | |
security: { src: 'security.svg' }, // Expected to be OK | |
email: { src: 'email.svg' }, // Expected to be OK | |
}; | |
function buildUi(builder: UiBuilder) { | |
builder(profileIcons).withIcon('security'); // Expected to be OK | |
builder(profileIcons).withIcon('bold'); // Expected to ERR | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment