Skip to content

Instantly share code, notes, and snippets.

@DethAriel
Last active February 13, 2018 20:36
Show Gist options
  • Save DethAriel/701830b6e0a99843bd19bcfbb18197c1 to your computer and use it in GitHub Desktop.
Save DethAriel/701830b6e0a99843bd19bcfbb18197c1 to your computer and use it in GitHub Desktop.
// 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