"The caller of the function specifies the type parameter, not the implementer"
If you refer back to my TypeScript version please note that I require Promise<T>.
Your version only gives me Promise<unknown>. The moment I put Promise<T> on rootAndRun() everything lights up red. The Promise<T> based on Factory<T> was the point of making rootAndRun() generic.
For Promise<unknown> we don't need generics to begin with. CodeSandbox
unknown is extremely useful under very specific circumstances but when overused it reminds me of the Java pre-Generic Object fiasco in terms of type safety.
that could be reused
How OO of you 😁
In this case reuse isn't the goal as this is only for testing support, so not being coupled via reuse (Beware of the Share) is a good thing.
Also in general I try to stick to the Rule of Three:
You must have looked at at least three systems to understand what is common across them (and therefore reusable)
It takes three times as much effort to make something reusable as to make it usable
You will receive payback after the third release.
In this case the goal was to "unroll" it enough to make it more understandable.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TIL: There needs to be a comma after the type parameter for an arrow function otherwise TS thinks it's JSX.
The error message I was fighting:
"Argument of type
T
is not assignable to parameter of typeT
.T
could be instantiated with an arbitrary type which could be unrelated toT
."CodeSandBox
Which seems to imply:
"The caller of the function specifies the type parameter, not the implementer"
If you refer back to my TypeScript version please note that I require
Promise<T>
.Your version only gives me
Promise<unknown>
. The moment I putPromise<T>
onrootAndRun()
everything lights up red. ThePromise<T>
based onFactory<T>
was the point of makingrootAndRun()
generic.For
Promise<unknown>
we don't need generics to begin with. CodeSandboxunknown
is extremely useful under very specific circumstances but when overused it reminds me of the Java pre-GenericObject
fiasco in terms of type safety.How OO of you 😁
In this case reuse isn't the goal as this is only for testing support, so not being coupled via reuse (Beware of the Share) is a good thing.
Also in general I try to stick to the Rule of Three:
In this case the goal was to "unroll" it enough to make it more understandable.