Skip to content

Instantly share code, notes, and snippets.

@fzed51
Created August 11, 2023 06:32
Show Gist options
  • Save fzed51/2d7f7945e73e6829fa9476c41e471ba8 to your computer and use it in GitHub Desktop.
Save fzed51/2d7f7945e73e6829fa9476c41e471ba8 to your computer and use it in GitHub Desktop.
Modificateur de propriété
const handler =
<K extends keyof Struct>(prop: K) =>
<V extends Struct[K]>(value: V) => {
onChange({
...struct,
[prop]: v,
});
};
import {handler} from './handler';
interface Struct {
a: string;
b: number;
}
handler('a')('1') // ✔
handler('b')(1) // ✔
handler('b')('1') // 𐄂
handler('a')(1) // 𐄂
handler('c')(1) // 𐄂
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment