-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[restrict-plus-operands] False positive reported when adding two numbers #624
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
I updated your example to include the line If there are type errors in your codebase, typescript will essentially resolve the type to Running the updated example against master works fine. for posterity, this was the code I ran against masterexport abstract class Legend
{
protected legendWidth: number = 244;
public get width(): number { return this.legendWidth; }
}
export abstract class Chart
{
protected static readonly svgcMargin: number = 10;
protected readonly legend: Legend;
}
// Code that is failing in a class that extends Chart
export class PieChart extends Chart
{
protected fn(): void
{
const thing = this.legend.width + Chart.svgcMargin;
}
} |
Sorry about that I was trying to manually cut down the example code and missed something out. I've updated with the code that I think should repro my issue, though in this example I can't get it to error for some reason. But I am most definitely seeing the issue in my code, despite both properties being explicitly defined as numbers. As I'm working with a private repo I am not able to share the full code that is giving me issues. It's quite large if I were to include everything. I have a theory that it might be something to do with the generated mapping file creating links to different cased files, and somehow this breaks some sort of type checking. As in some files refer to: /// <reference path="Chart.ts" /> And others refer to: /// <reference path="chart.ts" /> I'm not sure if this makes a difference, but I'll try updating my references and then seeing what happens. |
Yeah, that didn't fix it... |
There must be something misconfigured with your codebase. I just tested this against master and it worked fine: declare const UrlHelper : { encodeUriComponent(v: string): string }
const url = 'foo' + UrlHelper.encodeUriComponent('thing'); I suspect that when typescript is launched via the eslint run, it can't find all of your types, meaning it types all of those things are typed as Do you have multiple tsconfig files? Is your code in a monorepo (i.e. are there different |
It's a monorepo, that's set up to use Typescript projects. The I don't see how it can be an issue with the way we've set up our codebase, as typescript picks up the types of each of these variables and functions correctly. The weird thing about this issue is that it is not consistent. it is happening in multiple places, but not for all places where Is there any way of getting the output of estree to see what the type is being detected as? |
Sorry, I don't mean your codebase itself is misconfigured, I mean the eslint -> typescript integration is misconfigured somehow. I don't have enough knowledge of how typescript projects work to know what the issue is exactly. Could you try supplying each project's tsconfig to the |
I had the same problem with a yarn workspaces monorepo. const glob = require('glob')
const configs = glob.sync('./packages/**/tsconfig.json')
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: configs[0],
projects: configs
},
...
} All the other tsconfigs extend a base config that is at the root of the project. BUT using the base tslint config as the @bradzacher I was planning to switch from using a JS eslint config to using the yaml alternative file but it's no longer possible because of the runtime component. It would be very helpful to add a glob pattern option to parserOptions. Would you accept a PR that does this or should I open another issue for this to gather more feedback? |
Are you able to try installing the 2.0.0 canary ( We've put a fix into the new version which should hard error for files that aren't included within your project config. You'll be able to add a single tsconfig, and then keep adding in more as required. As an aside, part of me thinks that the easiest solution to this is to just create a tsconfig in the root of your project
{
"compilerOptions": { "strict": true },
"include": ["packages/**/*"],
"exclude": ["node_modules"]
} I'm not sure what is easier.
It's probably a good idea. Maybe you could set it up for the |
I have tried v2 and with the eslint config I had before and the files in question are being included and eslint still complains about However, if I add a file {
"compilerOptions": { "strict": true },
"include": ["packages/*"], // <-- packages/**/* doesn't seem to work (files are not being included)
"exclude": ["node_modules"]
} then the IMO the most elegant solution is to allow us to pass a glob pattern for the I got a question in regards to this: Why is it required to pass something to |
cc @uniqueiniquity, who has more context on how the ts compiler piece works. |
Hi all, There is no |
|
Yeah... |
Ohh, so that means I can provide the array of strings to the
Regarding this, the context was that I wanted to convert my eslint config from JS to YAML but I can't because of the runtime component (the glob that searches for all tsconfigs). Passing a glob would solve this. |
Sorry, I wasn't clear - I fully support it taking a glob :) |
No problem :) We should also mention here that |
@uniqueiniquity I got a few more questions: Does the parser have any IO functionality? I have looked at the source and it doesn't seem to be the case. If the current implementation is not dependent on IO, I think the glob stuff should only be implemented for the
Does On a side-note, I am planning to use |
@teoxoy It does depend on IO in the sense that if you provide one or more
Could you open a new issue to track this work? In case the original issue reported here continues to be a problem, I don't want to get too far away from the original topic. |
I was wondering because some parsers don't have any IO operations and can be used in other environments other than node. I only wanted to make sure this was out of scope for this project.
Sure Regarding In the
(in the |
I see. I think this project is specific to Node - @bradzacher can confirm. I'd suggest the glob functionality be in the |
If you provide We'd have to do some work to make it work fine in the browser with a project. |
Repro
Expected Result
No error
Actual Result
this.legend.width + Chart.svgcMargin
reports a false positiveVersions
@typescript-eslint/eslint-plugin
1.10.2
@typescript-eslint/parser
1.10.2
TypeScript
3.4.3
ESLint
5.16.0
The text was updated successfully, but these errors were encountered: