Skip to content
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

Incorrect typing in worktop/ws #68

Closed
dhrubabasu opened this issue Jul 7, 2021 · 4 comments
Closed

Incorrect typing in worktop/ws #68

dhrubabasu opened this issue Jul 7, 2021 · 4 comments

Comments

@dhrubabasu
Copy link

dhrubabasu commented Jul 7, 2021

This code:

import type {Handler} from 'worktop';
import {connect} from 'worktop/ws';

export const handler: Handler = async (request) => {
  const error = connect(request);
  if (error) return error;
};

produces the following Eslint errors:

  ✖    5:17  Unsafe call of an any typed value.                                   @typescript-eslint/no-unsafe-call
  ✖    6:14  Unsafe return of an any typed value.                                 @typescript-eslint/no-unsafe-return
@lukeed
Copy link
Owner

lukeed commented Jul 7, 2021

Sorry, I do not care the slightest about eslint. If you know exactly what it's complaining about I can look at fixing it, but I'm not going to investigate otherwise. Eslint is replaced by tsc directly -- at least for errors like this.

@dhrubabasu
Copy link
Author

dhrubabasu commented Jul 7, 2021

It's complaining about this: https://github.com/lukeed/worktop/blob/master/src/ws.d.ts#L47

Eslint reads connect with type any:

Screen Shot 2021-07-07 at 5 07 10 AM

@lukeed
Copy link
Owner

lukeed commented Jul 7, 2021

On your end, can you try this for the types file:

declare const connect: Handler;
export { connect };

@dhrubabasu
Copy link
Author

dhrubabasu commented Jul 7, 2021

Oh, that file doesn't have import type { Handler } from 'worktop'; at the top. Adding that fixes the issue on my end. I did have to modify the handler to this:

export const handler: Handler = async (request, response) => {
  const error = await connect(request, response);
  if (error) return error;
}

Screen Shot 2021-07-07 at 12 32 59 PM

Not a huge deal but could be a good idea to modify the connect type declaration to only require the request parameter as it does nothing with the response.

@lukeed lukeed closed this as completed in ed509df Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants