First thing: I know there are a lot of question and good answers about how to write, curried functions. What I am requesting here is to be able to curry generics.
This seems related to #10571, but I thing its a slightly different proposal.
For this example we use this interface and this simple Instance
interface Interface {numberKey: number, stringKey: string}
const instance: Interface = {numberKey: 1, stringKey: "a"}
What is expected
It would be greate to be abled to write a function like this
// 1. Take a key name and a value
// 2. Return a function, that takes an object,
// that has a key that matches the given value
const getTransformerA = <I><K extends keyof I>(key: K, value: I[K]) =>
(input: I) => input
// We now we should be able to use it like this
const transformerA1 = getTransformerA<Interface>( 'numberKey', 123 )
// And we expect an error here
const transformerA1 = getTransformerA<Interface>( 'stringKey', 123 )
The advantage of this, is that we get a return function, that is guaranteed to work with a certain interface, before we call the return function. Which is especially useful in cases, where we could loose typing, but still want to ensure compatibility with an interface.
But this syntax doesn't work and I seem unable to find a workaround.
First thing: I know there are a lot of question and good answers about how to write, curried functions. What I am requesting here is to be able to curry generics.
This seems related to #10571, but I thing its a slightly different proposal.
For this example we use this interface and this simple Instance
What is expected
It would be greate to be abled to write a function like this
The advantage of this, is that we get a return function, that is guaranteed to work with a certain interface, before we call the return function. Which is especially useful in cases, where we could loose typing, but still want to ensure compatibility with an interface.
But this syntax doesn't work and I seem unable to find a workaround.