#TypeScript ESLint: "Unsafe assignment of an error typed value" when using Socket in NestJS WebSocket
16 messages · Page 1 of 1 (latest)
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
add top of the file these line
Hi, did u fix issue?
i had same problem i have added or disable that property for that file any proper solution ?
can u explan about this?
why did u write there?
it goona disable that property of eslint for that file
It’s still not fixed.
I’d like to know if there are any solutions other than disabling this rule.
I don’t understand why the original code throws an error. From what I read in the documentation, the first parameter of handleConnection should be the WebSocket instance in use.
What type should I be using then?
Even if I just call a method that the client should normally have, like emit, it still throws an error.
It really seems like the issue is with the type of the client parameter.
https://typescript-eslint.io/rules/no-unsafe-assignment/
Errors are hard aren't they?
The documentation says you can’t assign a value of type any to another value.
In my screenshot, the handleConnection function is an implementation of OnGatewayConnection.
When I looked into the OnGatewayConnection interface, I found this code:
export interface OnGatewayConnection<T = any> {
handleConnection(client: T, ...args: any[]): any;
}
Since client is defined as a generic any by default, I thought that if I moved the Socket type from handleConnection(client: Socket) up to the class level, it would solve the problem:
export class AppGateway implements OnGatewayConnection<Socket> {}
But even after passing the generic parameter, the issue still wasn’t resolved.
Or is there something I’ve misunderstood?
now i see what you mean you ussually want to avoid this
but you can always
// @ts-ignore the line