array-like elements have default arguments which violate genericity
Describe the bug
I was reviewing https://github.com/faker-js/faker/pull/189/files and I noticed that randomize supports generic results, but there's an issue with the arguments having a default.
Consider:
const a = randomize<number>();
This would return a string, which violates the type.
Reproduction
Additional Info
No response
I assume the only way to really fix this, is to fully remove the default and force an argument to be passed in. This would be a breaking change.
It seems the violation happens when the argument is undefined / empty. Are we trying to achieve
const a: number = randomize<number>();
console.log(a); // 1
const b = randomize();
console.log(b); // "a"
or else we may have to think of other ways
It seems the violation happens when the argument is undefined / empty. Are we trying to achieve
const a: number = randomize<number>(); console.log(a); // 1 const b = randomize(); console.log(b); // "a"or else we may have to think of other ways
Yeah, but sadly this is not possible due to TS is only at compile time. So the generic cannot change runtime behavior :shrug: So we may just remove the default value for the parameter and then declare it as breaking change
It seems the violation happens when the argument is undefined / empty. Are we trying to achieve
const a: number = randomize<number>(); console.log(a); // 1 const b = randomize(); console.log(b); // "a"or else we may have to think of other ways
Yeah, but sadly this is not possible due to TS is only at compile time. So the generic cannot change runtime behavior 🤷 So we may just remove the default value for the parameter and then declare it as breaking change
Yes if we've to change it. At least, generic specialization in TS is not possible.
This function is marked as deprecated (for removal in v7) and we already want to get rid of the default ['a', 'b', 'c'] (#589)
So I'm not sure if it's worth working on this issue specifically
Maybe we should just close this issue?
Isn't #589 the fix for this issue?
Blocked by #893
Team Decision
Can be implemented without #893
We want this for v8.0