Created
August 11, 2023 06:32
-
-
Save fzed51/2d7f7945e73e6829fa9476c41e471ba8 to your computer and use it in GitHub Desktop.
Modificateur de propriété
This file contains hidden or 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
const handler = | |
<K extends keyof Struct>(prop: K) => | |
<V extends Struct[K]>(value: V) => { | |
onChange({ | |
...struct, | |
[prop]: v, | |
}); | |
}; |
This file contains hidden or 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
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