Skip to content

Commit 3ba9f06

Browse files
committed
build(eslint-plugin-react-hooks): tsconfig and global types
Contributing to facebook#32240, this change adds the tsconfig, tsup config, and estree type declarations that will be needed for that plugin's typescript migration.
1 parent a657bc5 commit 3ba9f06

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* This file augments the `estree` types to include types that are not built-in to `estree` or `estree-jsx`.
3+
* This is necessary because the `estree` types are used by ESLint, and ESLint does not natively support
4+
* TypeScript or Flow types. Since we're not using a ton of them, we can just add them here, rather than
5+
* installing typescript estree or flow estree types.
6+
*
7+
* This also adds support for the AST mutation that the Exhaustive deps rule does to add parent nodes.
8+
*/
9+
declare module 'estree' {
10+
// The Exhaustive deps rule mutates the AST to add parent nodes for efficient traversal.
11+
// We need to augment the `estree` types to support that.
12+
interface BaseNode {
13+
parent?: Node;
14+
}
15+
16+
// Adding types that aren't built-in to estree or estree-jsx.
17+
// Namely, the specific TS and Flow types that we're using.
18+
interface AsExpression extends BaseExpression {
19+
type: 'AsExpression';
20+
expression: Expression | Identifier;
21+
}
22+
23+
interface OptionalCallExpression extends BaseCallExpression {
24+
type: 'OptionalCallExpression';
25+
}
26+
27+
interface OptionalMemberExpression extends MemberExpression {
28+
type: 'OptionalMemberExpression';
29+
}
30+
31+
interface TSAsExpression extends BaseExpression {
32+
type: 'TSAsExpression';
33+
expression: Expression | Identifier;
34+
}
35+
36+
interface TSTypeQuery extends BaseNode {
37+
type: 'TSTypeQuery';
38+
exprName: Identifier;
39+
}
40+
41+
interface TSTypeReference extends BaseNode {
42+
type: 'TSTypeReference';
43+
typeName: Identifier;
44+
}
45+
46+
interface TypeCastExpression extends BaseExpression {
47+
type: 'TypeCastExpression';
48+
expression: Expression | Identifier;
49+
}
50+
51+
// Extend the set of known Expression types
52+
interface ExpressionMap {
53+
AsExpression: AsExpression;
54+
OptionalCallExpression: OptionalCallExpression;
55+
OptionalMemberExpression: OptionalMemberExpression;
56+
TSAsExpression: TSAsExpression;
57+
TypeCastExpression: TypeCastExpression;
58+
}
59+
60+
// Extend the set of known Node types
61+
interface NodeMap {
62+
AsExpression: AsExpression;
63+
OptionalCallExpression: OptionalCallExpression;
64+
OptionalMemberExpression: OptionalMemberExpression;
65+
TSAsExpression: TSAsExpression;
66+
TSTypeQuery: TSTypeQuery;
67+
TSTypeReference: TSTypeReference;
68+
TypeCastExpression: TypeCastExpression;
69+
}
70+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// In order to support the __EXPERIMENTAL__ global in TypeScript,
2+
// we need to declare it here. The value of this is set in both
3+
// the jest setup and CI build
4+
declare const __EXPERIMENTAL__: boolean;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "@tsconfig/strictest/tsconfig.json",
3+
"compilerOptions": {
4+
"module": "ES2015",
5+
"target": "ES2015",
6+
"moduleResolution": "Bundler",
7+
"lib": ["ES2020"],
8+
"rootDir": "../",
9+
"noEmit": true,
10+
"sourceMap": false,
11+
"types": ["estree-jsx", "node"]
12+
},
13+
"exclude": ["node_modules"],
14+
"include": ["src/**/*.ts"]
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {defineConfig} from 'tsup';
2+
3+
export default defineConfig({
4+
clean: true,
5+
dts: true,
6+
entry: ['src/index.ts'],
7+
format: ['cjs'],
8+
outDir: 'build',
9+
});

0 commit comments

Comments
 (0)