Skip to content

Commit b14447e

Browse files
authored
fix: web types (#8401)
Required for - #8371 ## Summary This PR is an ongoing effort to reduce the impact of Reanimated and Worklets in web bundles and to simplify the logic of platform-dependent code. The ideal solution is to have native-only files with a `.native.ts` extension and web only files with just `.ts` extension alongside them. However, currently we also have `.web.ts` files, which can be problematic in some environments. We want to transition to `.native.ts` files gradually. This PR does a few things: - It edits TSConfigs alongside the repository. By default we specify that accepted extensions are `.native.ts`, `.ios.ts`, `.android.ts`, `.ts` (obviously also `.tsx` etc.). This means that when in IDE we click `go to source` we'll go to a `.native` file which is the most common use case for us. Also types for type-checking will be pulled like this. - We add additional TSConfigs for web types. These extensions ignore `.native` .etc. extensions and accept `.web` extensions. You can switch to those TSConfigs for web type-checking in your IDE. - Adding type checking scripts and CI checks for web types. - Fixing (or ignoring) all current problems with web types - i.e. mismatching web and native types in Reanimated. - Amending eslint configs to properly work in this setup. ## Test plan CI
1 parent d700021 commit b14447e

File tree

74 files changed

+528
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+528
-131
lines changed

.github/actions/reanimated-typescript-compatibility-check/action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ runs:
1919
shell: bash
2020
run: yarn up react-native@${{ inputs.react-native-version }}
2121

22-
- name: Check source types
22+
- name: Check native source types
2323
shell: bash
2424
working-directory: packages/react-native-reanimated
25-
run: yarn type:check:src
25+
run: yarn type:check:src:native
26+
27+
- name: Check web source types
28+
shell: bash
29+
working-directory: packages/react-native-reanimated
30+
run: yarn type:check:src:web
2631

2732
- name: Check plugin types
2833
shell: bash

.lintstagedrc-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('lint-staged').Config} */
1+
/** @type {import('lint-staged').Configuration} */
22
module.exports = {
33
'*.(js|jsx|ts|tsx)': [
44
'yarn eslint --flag v10_config_lookup_from_file',

apps/common-app/.lintstagedrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/** @type {import('lint-staged').Config} */
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/** @type {import('lint-staged').Configuration} */
23
const commonConfig = require('../../.lintstagedrc-common.js');
34

4-
/** @type {import('lint-staged').Config} */
5+
/** @type {import('lint-staged').Configuration} */
56
module.exports = {
67
...commonConfig,
78
};

apps/common-app/eslint.config.mjs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import { fixupPluginRules } from '@eslint/compat';
12
import jsEslint from '@eslint/js';
2-
import tsEslint from 'typescript-eslint';
3-
import perfectionist from 'eslint-plugin-perfectionist';
4-
import reactNative from 'eslint-plugin-react-native';
5-
import react from 'eslint-plugin-react';
6-
import globals from 'globals';
73
import importPlugin from 'eslint-plugin-import';
4+
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
5+
import perfectionist from 'eslint-plugin-perfectionist';
86
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
7+
import react from 'eslint-plugin-react';
8+
// eslint-disable-next-line import/default
99
import reactHooks from 'eslint-plugin-react-hooks';
10-
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
10+
// @ts-expect-error eslint-plugin-react-native has no types.
11+
import reactNative from 'eslint-plugin-react-native';
1112
import simpleImportSort from 'eslint-plugin-simple-import-sort';
1213
import unusedImports from 'eslint-plugin-unused-imports';
13-
import { fixupPluginRules } from '@eslint/compat';
14-
import { globalIgnores } from 'eslint/config';
14+
import globals from 'globals';
15+
import tsEslint from 'typescript-eslint';
1516

1617
/** @type {import('typescript-eslint').ConfigWithExtends[]} */
1718
export default tsEslint.config(
@@ -21,14 +22,30 @@ export default tsEslint.config(
2122
eslintPluginPrettierRecommended,
2223
{
2324
languageOptions: {
25+
parserOptions: {
26+
parser: tsEslint.parser,
27+
project: [
28+
'./tsconfig.json',
29+
'./tsconfig.web.json',
30+
'./../../tsconfig.json',
31+
],
32+
tsconfigRootDir: import.meta.dirname,
33+
},
34+
},
35+
},
36+
{
37+
languageOptions: {
38+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2439
globals: {
2540
React: true,
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2642
...reactNative.environments['react-native']['react-native'],
2743
...globals.node,
2844
},
2945
},
3046
plugins: {
3147
'no-relative-import-paths': noRelativeImportPaths,
48+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
3249
'react-native': fixupPluginRules(reactNative),
3350
'simple-import-sort': simpleImportSort,
3451
'unused-imports': unusedImports,
@@ -267,7 +284,6 @@ export default tsEslint.config(
267284
'import/resolver': {
268285
typescript: {
269286
alwaysTryTypes: true,
270-
project: './tsconfig.json',
271287
},
272288
},
273289
react: {
@@ -276,15 +292,7 @@ export default tsEslint.config(
276292
},
277293
},
278294
{
279-
files: ['**/*.ts', '**/*.tsx'],
280295
extends: [tsEslint.configs.recommendedTypeChecked],
281-
languageOptions: {
282-
parserOptions: {
283-
parser: tsEslint.parser,
284-
project: './tsconfig.json',
285-
tsconfigRootDir: import.meta.dirname,
286-
},
287-
},
288296
rules: {
289297
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
290298
'@typescript-eslint/consistent-type-exports': 'error',
@@ -328,6 +336,5 @@ export default tsEslint.config(
328336
'@typescript-eslint/no-unsafe-member-access': 'error',
329337
'no-underscore-dangle': 'error',
330338
},
331-
},
332-
globalIgnores(['**/eslint.config.mjs'])
339+
}
333340
);

apps/common-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"lint": "eslint . --flag v10_config_lookup_from_file",
88
"format": "prettier --write --list-different .",
99
"circular-dependency-check": "yarn madge --extensions js,jsx,ts,tsx --circular src",
10-
"type:check": "tsc --noEmit",
10+
"type:check": "yarn type:check:native && yarn type:check:web",
11+
"type:check:native": "tsc --noEmit",
12+
"type:check:web": "tsc --noEmit --project tsconfig.web.json",
1113
"type:check:strict": "tsc --noEmit --customConditions react-native-strict-api"
1214
},
1315
"peerDependencies": {

apps/common-app/scripts/dependencies.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
3+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
4+
/* eslint-disable @typescript-eslint/no-require-imports */
15
const path = require('path');
26

37
/**

apps/common-app/src/apps/css/components/cards/ExpandableCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export default function ExpandableCard({
5050
style={[styles.overlay, { height: overlayHeight }]}>
5151
<Animated.View style={[styles.gradient, animatedGradientStyle]}>
5252
<Svg height={overlayHeight} width="100%">
53+
{/* TODO: Fix me */}
54+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
55+
{/* @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801 */}
5356
<Defs>
5457
<LinearGradient
5558
id="vertical-gradient"

apps/common-app/src/apps/css/components/inputs/TabSelector.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ function TabSelector<T extends string>({
8383
() => (
8484
<View pointerEvents="none" style={StyleSheet.absoluteFill}>
8585
<Svg>
86+
{/* TODO: Fix me */}
87+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
88+
{/* @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801 */}
8689
<Defs>
8790
<LinearGradient id="tab-selector" x1="0" x2="1" y1="0" y2="0">
8891
<Stop

apps/common-app/src/apps/css/examples/animations/routeCards/RealWorldExamplesCard.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ function Rocket({ size }: RocketProps) {
8484
return (
8585
<Svg
8686
viewBox="0 0 180 179" // Set the fixed viewBox based on the original SVG dimensions
87+
// TODO: Fix me
88+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
89+
// @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801
8790
style={{
8891
height: size,
8992
width: size,
9093
}}>
94+
{/* TODO: Fix me */}
95+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
96+
{/* @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801 */}
9197
<Defs>
9298
<LinearGradient id="rocket-card" x1="0" x2="1" y1="0" y2="0">
9399
<Stop offset="0" stopColor={colors.background2} />
@@ -131,6 +137,9 @@ type FlameProps = {
131137
function Flame({ height, width }: FlameProps) {
132138
return (
133139
<Svg height={height} width={width}>
140+
{/* TODO: Fix me */}
141+
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
142+
{/* @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801 */}
134143
<Defs>
135144
<LinearGradient id="flame-card" x1="0" x2="1" y1="0" y2="0">
136145
<Stop offset="0" stopColor={colors.primaryLight} />

apps/common-app/src/apps/css/examples/animations/screens/animatedProperties/svg/Circle.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Animated, { type CSSAnimationKeyframes } from 'react-native-reanimated';
2+
// TODO: Fix me
3+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4+
// @ts-ignore RNSVG doesn't export types for web, see https://github.com/software-mansion/react-native-svg/pull/2801
25
import { Circle, type CircleProps, Svg } from 'react-native-svg';
36

47
import { ExamplesScreen } from '@/apps/css/components';

0 commit comments

Comments
 (0)