-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
📚 New no-evolving-any
rule documentation lacks proper examples and/or references
#48
Comments
I don't have enough knowledge on this rule, please allow me to tag @Conaclos @fujiyamaorange to make sure this issue is noticed. |
@Sec-ant I'm not sure about @Conaclos's perspective on this matter, but I'd like to offer my own insight. Consider the following code snippet: const b = [];
b.push(1);
console.log(b); In this instance, TypeScript infers the type of b as any[], not as strictly typed array. Regarding the next example, let c = null;
c = 'hello';
console.log(c); Here, TypeScript infers c as having the type any once again. This demonstrates how TypeScript handles type inference in these scenarios." |
@bgenia you were involved in the original issue, so you have some context and knowledge. If so, would you like to send a PR to add some more explanation and examples? @fujiyamaorange feel free to send a PR that adds more examples. |
@ematipico |
There might be some misunderstanding. We need no hurry. I think what @bgenia suggests is evolving any shouldn't be banned at all if the user set The examples @fujiyamaorange proposed here will all be properly typed if To make things clear, evolving |
Unfortunately, we are not able to know if Even when it is enabled, you still have some potential issues. Because you allow the type to evolve in any direction. let x = [];
x[0] = 0;
x[0] = "a";
x; //: (number | string)[] Here is a summary of the inferred type according to TS settings:
I agree that the rule documentation should be updated. |
Yes, this is my point. Evolving any is only a thing when
Then this is not a
let x = [];
x[0] = 0;
x[0] = "a";
x; //: (number | string)[] So what are the issues here? The code is correct. Type system will only allow you to use
While it seems like let xs = []
let y: number[] = xs // Error: Variable 'xs' implicitly has an 'any[]' type |
You made a good point.
This looks like an error of mixing types. However, I accept that this is mostly a niche issue. This should certainly not justify the existence of the rule. let x = [];
x[0] = 0;
x[0] = "a";
accept(x);
function accept(x: any[]) {}
The reason d'être of this rule is a request of @jpike88 (#381). What I suggest:
|
@Conaclos, what are the next steps to close this issue? Do we need to update the documentation? |
Documentation URL
https://biomejs.dev/linter/rules/no-evolving-any
Description
Follow up on biomejs/biome#1883 biomejs/biome#2112
The docs currently state that evolving types may lead to variables with an any type, but lack any sort of examples which demonstrate this. It is also stated that evolving any disables many type-checking rules, also without any examples or references.
Expectations
What are the exact caveats of using evolving any? What are the examples?
From what I know, evolving any doesn't turn into any if not explicitly assigned as such. Just like it doesn't disable many type-checking rules. I might be wrong, but the docs lack any proofs or references.
Code of Conduct
The text was updated successfully, but these errors were encountered: