fix: Root tsconfig doesn't include anything useful and all type-tests in the repository are broken #8803
+5
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I found that all type tests (type-test.ts) in the repository are currently broken and do not test anything useful. I noticed this via intellisense when installing the repo locally to fix some other types: nearly everything is typed as
any.Analysing the problem
Current tsconfig only includes
packages/**/lib/*.d.ts. (Insight: this doesn't include nested folders underneath lib/) For all the packages I looked at, this only includes the index.d.ts but does not include other type declarations in nested folders. For example, the firestore package has a lot of *.d.ts within thefirestore/lib/modular/directory.In most cases, the
lib/index.d.tsfile will import types from those nested directories in the module.firestore/lib/index.d.tsimports fromfirestore/lib/modular/index.d.tsfor example. However, because those nested directories are not part of the tsconfig, they are treated as external dependencies. This is an issue because skipLibCheck is enabled. skipLibCheck ignores type errors in any external dependency, and changes the errored types to any. Oops, that includes all types from nested files within our modules!FInally, packages attempt to import each other's types. For example, all modules have
import { ReactNativeFirebase } from '@react-native-firebase/app'at the top. When installed as a dependency from NPM this is OK, as the imported module will be in node_modules and resolved correctly. However, when running tsc against the repo there's no way for the type checker to resolve these as they are not found in node_modules. You can verify this by checking intellisense in vscode after installing this repo, any time that a package's index.d.ts imports from@react-native-firebase/*you will see all the imported types becomeany.Solution
I have made these changes:
pathsdefinition to allow the modules to resolve each other when running tsc in the repo.After this change, the type-test.ts in most packages are broken. That's not caused by this change, in fact the tests are already wrong for many years and have just been masked by the
skipLibCheckissue (Since #5590 in 2021!!!). For example, most type-tests treatimport firebase from '.'as both a default import and as a star import, which is likely incorrect.The bottom line is: if
skipLibCheckis enabled, it is critically important to include all files you actually want to type check within the scope of a tsconfig.json which is used to runtsc. Otherwise they are treated as external deps and aren't checked at all, with all their types silently becominganywhen unresolved.Related issues
Release Summary
Checklist
AndroidiOSOther(macOS, web)e2etests added or updated inpackages/\*\*/e2ejesttests added or updated inpackages/\*\*/__tests__Test Plan
Does not affect any user-facing code. tsc is not used anywhere to compile code (noEmit is set). Just makes the type tests in the repository actually functional. They should be fixed individually later.
Think
react-native-firebaseis great? Please consider supporting the project with any of the below:React Native FirebaseandInvertaseon Twitter