Skip to content

Instantly share code, notes, and snippets.

@Gikkman
Created February 11, 2020 09:29
Show Gist options
  • Select an option

  • Save Gikkman/eaa5c154ab31809d89b3c06dbc129193 to your computer and use it in GitHub Desktop.

Select an option

Save Gikkman/eaa5c154ab31809d89b3c06dbc129193 to your computer and use it in GitHub Desktop.
example.ts
interface example {
"a": number,
"b": string,
"c": {x: number, y: string, z: any },
"d": {val: keyof example}
}
function test<T extends keyof example> (p1: T, p2: example[T]): void {
console.log(p1, p2);
}
test("a", 1);
test("b", "hej");
test("c", {x:1, y:"hej", z: undefined});
test("d", {val: "a"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment