I am trying to gain a better understanding of how to utilize the infer
keyword in TypeScript.
Is this an appropriate example demonstrating the correct usage of infer?
I simply want to infer the return type of the function below:
const [name, setName] = useState<string>('');
const [age, setAge] = useState<number>();
type CallbackType<T> = T extends () => infer R ? R: never
function stateCallback<T>(name: string, age: number): CallbackType<T>{
setName(name)
setAge(age);
}
Since I am not returning anything, it should result in a void type. Is this the correct use of the infer
keyword?