eslint-webpack-plugin
eslint-webpack-plugin copied to clipboard
in webpack-dev-server, rule `@typescript-eslint/no-unsafe-assignment` throws an error when an imported type changed
Bug report
- in
webpack-dev-serverdevelopment mode(watch), when the rule@typescript-eslint/no-unsafe-assignmentis enabled - given a type in one file, given an object with this type imported in another file
- run the
webpack-dev-server, it compiled successfully. - 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?
- create a repo by
create-react-app. - enable the rule
@typescript-eslint/no-unsafe-assignmentin any way. - add a file named
type.tsor whatever, export a type like this:
export type IObj {
name: string;
age: number;
}
- in
index.tsx, we do this:
import { IObj } from './types';
let obj: IObj = {
age: 13,
name: '123',
};
const _name = obj.name;
everything is ok now.
- most important step: we add a property for
IObjand 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;
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
Hi @Arichy Could you provide a repository?
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.
Hi @Arichy Sorry for delay... I couldn't reproduce, if the problem persists reopen.
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
Problem does not occur in the latest versions