Skip to content

Commit 7e5aeb1

Browse files
committed
fix typecheck React 18
1 parent 3962c4c commit 7e5aeb1

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Setup deps (React 18)
2+
description: Setup Node.js and install dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup Node.js
8+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
9+
with:
10+
node-version-file: .nvmrc
11+
12+
- name: Cache deps
13+
id: yarn-cache
14+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
15+
with:
16+
path: |
17+
./node_modules
18+
.yarn/install-state.gz
19+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
20+
restore-keys: |
21+
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
22+
${{ runner.os }}-yarn-
23+
24+
- name: Install deps
25+
if: steps.yarn-cache.outputs.cache-hit != 'true'
26+
run: yarn install --immutable
27+
shell: bash
28+
29+
- name: Switch to React 18
30+
run: |
31+
yarn add -D react@18.3.1 react-test-renderer@18.3.1 @types/react@18.3.1 @types/react-test-renderer@18.3.1 react-native@0.77.0 @react-native/babel-preset@0.77.0
32+
shell: bash

.github/workflows/ci.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ jobs:
4848
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4949

5050
- name: Setup Node.js and deps
51-
uses: ./.github/actions/setup-deps
52-
53-
- name: Switch to React 18
54-
run: |
55-
yarn add -D react@18.3.1 react-test-renderer@18.3.1 react-native@0.77.0 @react-native/babel-preset@0.77.0
51+
uses: ./.github/actions/setup-deps-react-18
5652

5753
- name: Typecheck
5854
run: yarn typecheck
@@ -83,11 +79,7 @@ jobs:
8379
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8480

8581
- name: Setup Node.js and deps
86-
uses: ./.github/actions/setup-deps
87-
88-
- name: Switch to React 18
89-
run: |
90-
yarn add -D react@18.3.1 react-test-renderer@18.3.1 react-native@0.77.0 @react-native/babel-preset@0.77.0
82+
uses: ./.github/actions/setup-deps-react-18
9183

9284
- name: Test
9385
run: yarn test:ci

src/__tests__/render-hook-async.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ afterEach(() => {
1313
console.error = originalConsoleError;
1414
});
1515

16+
function useSuspendingHook(promise: Promise<string>) {
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+
// @ts-ignore: React 18 does not have `use` hook
19+
return React.use(promise);
20+
}
21+
1622
test('renderHookAsync renders hook asynchronously', async () => {
1723
const { result } = await renderHookAsync(() => {
1824
const [state, setState] = React.useState(1);
@@ -124,10 +130,6 @@ test('handles multiple state updates in effects', async () => {
124130
});
125131

126132
testGateReact19('handles hook with suspense', async () => {
127-
function useSuspendingHook(promise: Promise<string>) {
128-
return React.use(promise);
129-
}
130-
131133
let resolvePromise: (value: string) => void;
132134
const promise = new Promise<string>((resolve) => {
133135
resolvePromise = resolve;
@@ -169,10 +171,6 @@ testGateReact19('handles hook suspense with error boundary', async () => {
169171
// eslint-disable-next-line no-console
170172
console.error = excludeConsoleMessage(console.error, ERROR_MESSAGE);
171173

172-
function useSuspendingHook(promise: Promise<string>) {
173-
return React.use(promise);
174-
}
175-
176174
let rejectPromise: (error: Error) => void;
177175
const promise = new Promise<string>((_resolve, reject) => {
178176
rejectPromise = reject;

src/__tests__/suspense-fake-timers.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ afterEach(() => {
1616
});
1717

1818
function Suspending({ promise, testID }: { promise: Promise<unknown>; testID: string }) {
19+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
20+
// @ts-ignore React 18 does not have `use` hook
1921
React.use(promise);
2022
return <View testID={testID} />;
2123
}

src/__tests__/suspense.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ afterEach(() => {
1414
});
1515

1616
function Suspending({ promise, testID }: { promise: Promise<unknown>; testID: string }) {
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+
// @ts-ignore React 18 does not have `use` hook
1719
React.use(promise);
1820
return <View testID={testID} />;
1921
}

0 commit comments

Comments
 (0)