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

Do not require specifying "void" and "Promise<void>" return types #8832

Closed
ry opened this issue Dec 19, 2020 · 2 comments · Fixed by #11577
Closed

Do not require specifying "void" and "Promise<void>" return types #8832

ry opened this issue Dec 19, 2020 · 2 comments · Fixed by #11577
Labels
tests related to tests

Comments

@ry
Copy link
Member

ry commented Dec 19, 2020

We should strive for concise code. void and Promoise<void> return types are unnecessary boilerplate.

Example:

Deno.test({
  name: "Worker with top-level-await",
  fn: async function (): Promise<void> {  // <--- HERE
    const promise = deferred();
    const worker = new Worker(
      new URL("./worker_with_top_level_await.ts", import.meta.url).href,
      { deno: true, type: "module" },
    );
    worker.onmessage = (e): void => {    // <--- HERE
      console.log("received from worker", e.data);
      worker.postMessage("from main");
      promise.resolve();
    };
    await promise;
    worker.terminate();
  },
});
@ry ry changed the title Do not require specifying "void" and "Promise<void>" return values Do not require specifying "void" and "Promise<void>" return types Dec 19, 2020
@kitsonk
Copy link
Contributor

kitsonk commented Dec 19, 2020

I believe we dropped the linting rule requiring explicit return type annotations. I will check later but I believe this compiles and passes linting:

Deno.test({
  name: "Worker with top-level-await",
  aync fn() {
    const promise = deferred();
    const worker = new Worker(
      new URL("./worker_with_top_level_await.ts", import.meta.url).href,
      { deno: true, type: "module" },
    );
    worker.onmessage = (e) => {
      console.log("received from worker", e.data);
      worker.postMessage("from main");
      promise.resolve();
    };
    await promise;
    worker.terminate();
  },
});

@kitsonk
Copy link
Contributor

kitsonk commented Dec 21, 2020

@ry I checked, the following passes type checking and deno lint fine:

import { deferred } from "https://deno.land/std@0.81.0/async/deferred.ts";

Deno.test({
  name: "Worker with top-level-await",
  async fn() {
    const promise = deferred();
    const worker = new Worker(
      new URL("./worker_with_top_level_await.ts", import.meta.url).href,
      { deno: true, type: "module" },
    );
    worker.onmessage = (e) => {
      console.log("received from worker", e.data);
      worker.postMessage("from main");
      promise.resolve();
    };
    await promise;
    worker.terminate();
  },
});

Any concerns with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests related to tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants