Repository: facebook/react
Pull request: build(eslint-plugin-react-hooks): tsconfig and global types

<!--
  Thanks for submitting a pull request!
  We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory.

  Before submitting a pull request, please make sure the following is done:

  1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`.
  2. Run `yarn` in the repository root.
  3. If you've fixed a bug or added code that should be tested, add tests!
  4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
  5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`.
  6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect".
  7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`).
  8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

  Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Contributing to https://github.com/facebook/react/pull/32240, this change adds the tsconfig, tsup config, and estree type declarations that will be needed for that plugin's typescript migration.


Changed files:
filename: packages/eslint-plugin-react-hooks/src/types/estree.d.ts
patch: @@ -0,0 +1,70 @@
+/**
+ * This file augments the `estree` types to include types that are not built-in to `estree` or `estree-jsx`.
+ * This is necessary because the `estree` types are used by ESLint, and ESLint does not natively support
+ * TypeScript or Flow types.  Since we're not using a ton of them, we can just add them here, rather than
+ * installing typescript estree or flow estree types.
+ *
+ * This also adds support for the AST mutation that the Exhaustive deps rule does to add parent nodes.
+ */
+declare module 'estree' {
+  // The Exhaustive deps rule mutates the AST to add parent nodes for efficient traversal.
+  // We need to augment the `estree` types to support that.
+  interface BaseNode {
+    parent?: Node;
+  }
+
+  // Adding types that aren't built-in to estree or estree-jsx.
+  // Namely, the specific TS and Flow types that we're using.
+  interface AsExpression extends BaseExpression {
+    type: 'AsExpression';
+    expression: Expression | Identifier;
+  }
+
+  interface OptionalCallExpression extends BaseCallExpression {
+    type: 'OptionalCallExpression';
+  }
+
+  interface OptionalMemberExpression extends MemberExpression {
+    type: 'OptionalMemberExpression';
+  }
+
+  interface TSAsExpression extends BaseExpression {
+    type: 'TSAsExpression';
+    expression: Expression | Identifier;
+  }
+
+  interface TSTypeQuery extends BaseNode {
+    type: 'TSTypeQuery';
+    exprName: Identifier;
+  }
+
+  interface TSTypeReference extends BaseNode {
+    type: 'TSTypeReference';
+    typeName: Identifier;
+  }
+
+  interface TypeCastExpression extends BaseExpression {
+    type: 'TypeCastExpression';
+    expression: Expression | Identifier;
+  }
+
+  // Extend the set of known Expression types
+  interface ExpressionMap {
+    AsExpression: AsExpression;
+    OptionalCallExpression: OptionalCallExpression;
+    OptionalMemberExpression: OptionalMemberExpression;
+    TSAsExpression: TSAsExpression;
+    TypeCastExpression: TypeCastExpression;
+  }
+
+  // Extend the set of known Node types
+  interface NodeMap {
+    AsExpression: AsExpression;
+    OptionalCallExpression: OptionalCallExpression;
+    OptionalMemberExpression: OptionalMemberExpression;
+    TSAsExpression: TSAsExpression;
+    TSTypeQuery: TSTypeQuery;
+    TSTypeReference: TSTypeReference;
+    TypeCastExpression: TypeCastExpression;
+  }
+}

filename: packages/eslint-plugin-react-hooks/src/types/global.d.ts
patch: @@ -0,0 +1,4 @@
+// In order to support the __EXPERIMENTAL__ global in TypeScript,
+// we need to declare it here.  The value of this is set in both
+// the jest setup and CI build
+declare const __EXPERIMENTAL__: boolean;

filename: packages/eslint-plugin-react-hooks/tsconfig.json
patch: @@ -0,0 +1,15 @@
+{
+  "extends": "@tsconfig/strictest/tsconfig.json",
+  "compilerOptions": {
+    "module": "ES2015",
+    "target": "ES2015",
+    "moduleResolution": "Bundler",
+    "lib": ["ES2020"],
+    "rootDir": ".",
+    "noEmit": true,
+    "sourceMap": false,
+    "types": ["estree-jsx", "node"]
+  },
+  "exclude": ["node_modules"],
+  "include": ["src/**/*.ts"]
+}

filename: packages/eslint-plugin-react-hooks/tsup.config.ts
patch: @@ -0,0 +1,9 @@
+import {defineConfig} from 'tsup';
+
+export default defineConfig({
+  clean: true,
+  dts: true,
+  entry: ['src/index.ts'],
+  format: ['cjs'],
+  outDir: 'build',
+});