Skip to content

0.11.0

Compare
Choose a tag to compare
@arcticicestudio arcticicestudio released this 14 Apr 07:38
· 6 commits to main since this release
v0.11.0

Changelog for the official Arctic Ice Studio JavaScript code style.

0.11.0

Release Date: 2021-04-14 Project Board Milestone

Show all commits

Improvements

Allow void operator as a statement for React Hooks#55#56 (⊶ af9c38b)

↠ To run async code in a React useEffect Hook the official React Hook FAQ section about how to fetch data recommends and shows in a demo how to define a scoped fat arrow function and run it immediately. Unfortunately this collided with the @typescript/no-floating-promises rule because the returned Promise of the called function must not be handled anymore.

useEffect(() => {
  const init = async () => {
    try {
      const data = await fetchData();
      setInitialized(isInit);
      if (data) initStores(data);
    } catch (err) {
      handleError(err);
    }
  };
  // This will trigger the "@typescript/no-floating-promises" rule because the returned "Promise" is not handled.
  init();
}, [fetchData, handleError, initStores, setInitialized]);

Explicitly disabling the rule for these specific code lines would have been an option, but it is recommended to use the void operator instead.

// ...
// This will trigger the "no-void" rule because the "void" operator is currently not allowed as a statement.
void init();
// ...

However, the no-void rule did not allow the void operator to be used as statement which resulted in this rule to also throw an error.
To resolve both problems, the allowAsStatement option of the no-void rule has been enabled.

Also see typescript-eslint/typescript-eslint#1184 where this solution is also recommended by one of the @typescript-eslint package maintainers.

The full changelog is available in the repository

Copyright © 2016-present Sven Greb