Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Created July 25, 2018 08:30
Show Gist options
  • Select an option

  • Save tlaitinen/cdb0be73e96104530c4d9f485ed0b708 to your computer and use it in GitHub Desktop.

Select an option

Save tlaitinen/cdb0be73e96104530c4d9f485ed0b708 to your computer and use it in GitHub Desktop.
function f<A>(k:keyof A) {
return {
setValue: (a:A, v:A[typeof k]) => Object.assign({}, a, {[k]: v}),
getValue: (a:A) => a[k]
};
}
interface B {
s: string;
n: number;
}
const bs = f<B>('s');
const bn = f<B>('n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment