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

lint: set @typescript-eslint/no-misused-promises to warn level #233

Open
hcfw007 opened this issue Jul 24, 2023 · 0 comments
Open

lint: set @typescript-eslint/no-misused-promises to warn level #233

hcfw007 opened this issue Jul 24, 2023 · 0 comments

Comments

@hcfw007
Copy link
Member

hcfw007 commented Jul 24, 2023

In current puppet-implementation.ts, there are lots of @typescript-eslint/no-misused-promises problems.

According to https://stackoverflow.com/questions/63488141/promise-returned-in-function-argument-where-a-void-return-was-expected, and handleUnaryCall definition

export type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;

The return type for handleUnaryCall should be void, not Promise<void>.

So we should change the puppet-implementation methods to this. Take contactAlias as example:

   contactAlias: (call, callback) => {
      void (async () => {
        log.verbose('PuppetServiceImpl', 'contactAlias()')

        const id = call.request.getId()

        /**
         * Set
         */
        if (call.request.hasAlias()) {
          try {
            await puppet.contactAlias(id, call.request.getAlias())
            return callback(null, new  grpcPuppet.ContactAliasResponse())
          } catch (e) {
            return grpcError('contactAlias', e, callback)
          }
        }

        /**
         * Get
         */
        try {
          const alias = await puppet.contactAlias(id)

          const response = new grpcPuppet.ContactAliasResponse()
          response.setAlias(alias)

          return callback(null, response)
        } catch (e) {
          return grpcError('contactAlias', e, callback)
        }
      })()
    },

This ensures that the implicit return of the callback remains undefined, rather than being a promise.

refs:
https://typescript-eslint.io/rules/no-misused-promises/
https://stackoverflow.com/questions/63488141/promise-returned-in-function-argument-where-a-void-return-was-expected

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

1 participant