eslint-webpack-plugin icon indicating copy to clipboard operation
eslint-webpack-plugin copied to clipboard

in webpack-dev-server, rule `@typescript-eslint/no-unsafe-assignment` throws an error when an imported type changed

Open Arichy opened this issue 3 years ago • 4 comments
trafficstars

Bug report

  1. in webpack-dev-server development mode(watch), when the rule @typescript-eslint/no-unsafe-assignment is enabled
  2. given a type in one file, given an object with this type imported in another file
  3. run the webpack-dev-server, it compiled successfully.
  4. add a new property for the type and the object, then get the added property from the object and assign the property to another variable, save, the rule will throw an error Unsafe assignment of an any value.

Actual Behavior

As above.

Expected Behavior

It should not throw the error, because the type of added property is specific, not any.

How Do We Reproduce?

  1. create a repo by create-react-app.
  2. enable the rule @typescript-eslint/no-unsafe-assignment in any way.
  3. add a file named type.ts or whatever, export a type like this:
export type IObj {
  name: string;
  age: number;
}
  1. in index.tsx, we do this:
import { IObj } from './types';

let obj: IObj = {
  age: 13,
  name: '123',
};

const _name = obj.name;
image

everything is ok now.

  1. most important step: we add a property for IObj and assign it to a variable
// type.ts
export type IObj {
  name: string;
  age: number;
  newProp: number;
}
// index.tsx
import { IObj } from './types';

let obj: IObj = {
  age: 13,
  name: '123',
  newProp: 1,
};

const _name = obj.name;
const _newProp = obj.newProp; 
image

Now, eslint will throw an error for this line, because eslint had not detected that IObj imported from another file changed. It regarded obj.newProp as any rather than string.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System: OS: macOS 12.5 CPU: (10) x64 Apple M1 Pro Memory: 366.68 MB / 32.00 GB Binaries: Node: 14.15.4 - ~/.volta/tools/image/node/14.15.4/bin/node Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn npm: 6.14.10 - ~/.volta/tools/image/node/14.15.4/bin/npm Browsers: Chrome: 104.0.5112.79 Firefox: 103.0.1 Safari: 15.6 Packages: babel-loader: ^8.2.3 => 8.2.5 case-sensitive-paths-webpack-plugin: ^2.4.0 => 2.4.0 css-loader: ^6.5.1 => 6.7.1 css-minimizer-webpack-plugin: ^3.2.0 => 3.4.1 eslint-webpack-plugin: ^3.1.1 => 3.2.0 file-loader: ^6.2.0 => 6.2.0 html-webpack-plugin: ^5.5.0 => 5.5.0 postcss-loader: ^6.2.1 => 6.2.1 resolve-url-loader: ^4.0.0 => 4.0.0 sass-loader: ^12.3.0 => 12.6.0 source-map-loader: ^3.0.0 => 3.0.1 style-loader: ^3.3.1 => 3.3.1 terser-webpack-plugin: ^5.2.5 => 5.3.3 webpack: ^5.64.4 => 5.74.0 webpack-dev-server: ^4.6.0 => 4.9.3 webpack-manifest-plugin: ^4.0.2 => 4.1.1 workbox-webpack-plugin: ^6.4.1 => 6.5.4

Arichy avatar Aug 03 '22 17:08 Arichy

Hi @Arichy Could you provide a repository?

ricardogobbosouza avatar Sep 30 '22 19:09 ricardogobbosouza

Hi @Arichy Could you provide a repository?

Here is my demo repo: https://github.com/Arichy/eslint-bug-report The way to reproduce is in README.md. Remember to save after each editing.

Arichy avatar Oct 01 '22 03:10 Arichy

Hi @Arichy Sorry for delay... I couldn't reproduce, if the problem persists reopen.

ricardogobbosouza avatar Feb 03 '23 14:02 ricardogobbosouza

Hi @ricardogobbosouza Here is the screen record, the probability of reproduce is about 70%. https://user-images.githubusercontent.com/29599723/217265820-15e5deed-325f-4c9e-81fb-50df58009467.mp4

Arichy avatar Feb 07 '23 14:02 Arichy

Problem does not occur in the latest versions

ricardogobbosouza avatar May 03 '24 15:05 ricardogobbosouza