-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Improvement suggestion: Accidental assignment instead of == when using .filter() is not reported as compile error #36529
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
Comments
Hah, but look at this: https://www.typescriptlang.org/play/#code/NoRgNABATJDMC6A6AZgSwDYBcCmAnAFAHYCuAthALwB8ERZl0AlIwLABQ7AbgIa4QCe7dNkwQAHgC5ajSjQBGAewXDuhBvhnVa-BiFZthogF5S6pKSVJy8m+UpVqKtS7edkKeoA If I try it with lambda, it is a compile error: var y
let x: () => boolean = () => (y = 1)
let z: (num: number) => boolean = (num) => (num=1) but inside the filter(), no error reported ... strange 🤔 |
|
Ah, ok, now I get it |
Also relevant: #18497 and eslint's |
If you're new to JS it's unlikely you're going to find novel or unexplored issues in TS - please try Stack Overflow first. Thanks! |
TypeScript Version: 3.7.5
Search Terms:
Accidental assignment using filter, boolean lambda, assignment lambda
Code
Expected behavior:
Compile error, since what I wanted was:
num == 2
Actual behavior:
No compile error.
Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=31&pln=1&pc=1#code/NoRgNATGDMC6B0AzAlgGwC4FMBOAKAdgK4C2ABALwB8pRZ5pEAlEA
Notes
I am mainly a Kotlin/Java guy, so I am not sure if
num = 2
is a boolean expression in JS, but anyway it feels wrong to me that this was allowed by TS, since it caused an unintentional silent bug in my code which took me some time to figure out.The text was updated successfully, but these errors were encountered: