Coming from C#. How do we return default value of generic parameter in Typescript? For example here is an utterly useless function in C#:
private T TwiceAsMuch<T>(T number)
{
if (number is int n)
return (T)(object)(n * 2);
else if (number is float f)
return (T)(object)(f * 2);
else
return default;
}
How do I achieve this last line return default
in Typescript?
Context
I'm writing a little wrapper function that performs axios.post
and returns the response in the type specified by the caller:
private static async postInternal<T>(route: string, data: unknown): Promise<T> {
await Vue.$axios.get('/sanctum/csrf-cookie')
const res = await Vue.$axios.post<T>(`${route}`, data)
.then(res => res.data)
.catch(err => {
openErr(err)
return ???
})
}
What goes in place of ???
?