-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): enable TypeScript libCheck & resolve type conflicts #4306
fix(types): enable TypeScript libCheck & resolve type conflicts #4306
Conversation
"dom" conflicts with @types/react-native
… than module declarations with namespace extensions
…se` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging
…eferring to interface keys
"Function" is not generic
Keep current behavior with `any`
Only allowed in implementations
…r `setBackgroundMessageHandler`
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/invertase/react-native-firebase/19f7umkno |
Here is a gist of each package's changes in patch files for use with https://gist.github.com/davidgovea/2feea6af41b41f76fae1a9c14465cb69 |
6c17ed0
to
0ec9750
Compare
@mikehardy It looks like the automatic patch creation is having issues: patches were only generated for The others have errors like: |
🤦 thanks for pointing that out - it's relatively new but I swear it was working when I tested it. Back to the workbench! |
…arcodeDetectorTypes
…herited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex
Incorrect type is now caught by TS
…ypes VisionBarcodeFormat.ALL_POINTS does not exist
0ec9750
to
c2e8023
Compare
Made an improvement to the Updated the patches in my gist as well. |
Side note we should probably run this script https://github.com/invertase/react-native-firebase/blob/master/website/scripts/generate-typedoc.js as part of the |
Thanks for reviewing @Salakar! This is popping up because of the older version of TypeScript being used in this portion of the project (3.5.3) vs the root project's TS improved recursive types a lot in 3.7 (see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#more-recursive-type-aliases and microsoft/TypeScript#33050), and they make a lot of sense for the Firestore definitions, so it seems to me that upgrading typedoc is appropriate. I'll make an attempt. Another TS feature that I wished was available for the |
Well, that didn't go as planned. Typedoc is currently locked to I'll be looking into it more when I have some more time to circle back. |
Honest question: why not bump to typescript 4.x? I'm not aware of compatibility issues (I just bump typescript whenever it comes out since it has never caused me problems, and RNFB is fully working for me with typescript "current stable" (4.x whatever it is right now) As a developer dependency that is just an optional support for the package I'd be +1 on bumping typescript all over. Historically I believe we have treated type breaks as a minor version ? if it is clearly documented we bumped minimum typescript version that would be okay with me but I'm also in the "version numbers are free" school of thought so could do semver major if needed (with same need for a clear breaking change / exact step to migrate snip in the changelog - easy to do) |
Alrighty -- the website is building properly. I don't have access to the vercel action info, but I have tested locally and things are looking good. Updated to the latest version of Typedoc, and added the one required change: a new @mikehardy -- I agree. I actually did bump TS to v4 in another side-branch, and things seemed fine. Just didn't want to overload this PR with extras. |
uses new syntax: TSConfigReader
15d0751
to
176fb12
Compare
getToken(authorizedEntity?: string, scope?: string = 'FCM'): Promise<string>; | ||
getToken(authorizedEntity?: string, scope?: string): Promise<string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting - this default string value you are removing has some relation to this issue: #3714
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mikehardy -- the place that the default scope = 'FCM'
is set is in the JS code here: https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/lib/index.js#L142-L159.
.d.ts
definitions have no runtime responsibilities: parameter defaults are not allowed.
If changing the default scope is a change needed in #3714, it needs to happen in the source file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes definitely - I just thought it was interesting the 'FCM' scoped was baked in here as well, and since it's an active discussion item I was cross-linking for cross-pollination. I commented over there that I'd love a PR to do the actual change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note I scanned through these again they all seem reasonable. Going to test the patches now in my work project since otherwise the type checks here aren't very robust I don't think. I'm mostly interested in whether these cause any breaking changes or not, for correct callouts in release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I integrated all the patches in my work project and everything seems fine, no type breaks there. I'm not able to set skipLibCheck to false in my project due to other problems, but none of them were in react-native-firebase after this change
…rtase#4306) * chore: enable TypeScript libcheck & remove "dom" lib "dom" conflicts with @types/react-native * chore: add react types (referenced by admob types) * refactor(types, app): move "app" exports to top-level exports, rather than module declarations with namespace extensions * refactor(types): use top-level exports for module types, rather than declarations * refactor(types): for JSON config, augment existing `ReactNativeFirebase` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging * fix(types, admob): Use string-indexing rather than dot-notation for referring to interface keys * fix(types, analytics): convert missing interface to `any` * fix(types, database): missing `value` type (treated as 'any') * fix(types, dynamic-links): fix dynamic-links `onLink` function type "Function" is not generic * fix(types, firestore): add missing generic to Promise type Keep current behavior with `any` * fix(types, messaging): remove parameter initializer in typedef Only allowed in implementations * fix(types, messaging): avoid implicit `any` via `void` return type for `setBackgroundMessageHandler` * fix(types, ml-vision): import non-ambient types in BarcodeDetectorTypes * fix(types, ml-vision): import non-ambient types in root module from BarcodeDetectorTypes * fix(types, ml-vision): repair invalid `extends` use by duplicating inherited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex * fix(types, perf): add void return types to untyped perf methods * tests(admob): add type override to intentionally-wrong syntax Incorrect type is now caught by TS * tests(types, ml-vision): fix ml-vision test typo, exposed by proper types VisionBarcodeFormat.ALL_POINTS does not exist * chore(website): update typedoc to allow recursive types uses new syntax: TSConfigReader
…rtase#4306) * chore: enable TypeScript libcheck & remove "dom" lib "dom" conflicts with @types/react-native * chore: add react types (referenced by admob types) * refactor(types, app): move "app" exports to top-level exports, rather than module declarations with namespace extensions * refactor(types): use top-level exports for module types, rather than declarations * refactor(types): for JSON config, augment existing `ReactNativeFirebase` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging * fix(types, admob): Use string-indexing rather than dot-notation for referring to interface keys * fix(types, analytics): convert missing interface to `any` * fix(types, database): missing `value` type (treated as 'any') * fix(types, dynamic-links): fix dynamic-links `onLink` function type "Function" is not generic * fix(types, firestore): add missing generic to Promise type Keep current behavior with `any` * fix(types, messaging): remove parameter initializer in typedef Only allowed in implementations * fix(types, messaging): avoid implicit `any` via `void` return type for `setBackgroundMessageHandler` * fix(types, ml-vision): import non-ambient types in BarcodeDetectorTypes * fix(types, ml-vision): import non-ambient types in root module from BarcodeDetectorTypes * fix(types, ml-vision): repair invalid `extends` use by duplicating inherited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex * fix(types, perf): add void return types to untyped perf methods * tests(admob): add type override to intentionally-wrong syntax Incorrect type is now caught by TS * tests(types, ml-vision): fix ml-vision test typo, exposed by proper types VisionBarcodeFormat.ALL_POINTS does not exist * chore(website): update typedoc to allow recursive types uses new syntax: TSConfigReader
…rtase#4306) * chore: enable TypeScript libcheck & remove "dom" lib "dom" conflicts with @types/react-native * chore: add react types (referenced by admob types) * refactor(types, app): move "app" exports to top-level exports, rather than module declarations with namespace extensions * refactor(types): use top-level exports for module types, rather than declarations * refactor(types): for JSON config, augment existing `ReactNativeFirebase` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging * fix(types, admob): Use string-indexing rather than dot-notation for referring to interface keys * fix(types, analytics): convert missing interface to `any` * fix(types, database): missing `value` type (treated as 'any') * fix(types, dynamic-links): fix dynamic-links `onLink` function type "Function" is not generic * fix(types, firestore): add missing generic to Promise type Keep current behavior with `any` * fix(types, messaging): remove parameter initializer in typedef Only allowed in implementations * fix(types, messaging): avoid implicit `any` via `void` return type for `setBackgroundMessageHandler` * fix(types, ml-vision): import non-ambient types in BarcodeDetectorTypes * fix(types, ml-vision): import non-ambient types in root module from BarcodeDetectorTypes * fix(types, ml-vision): repair invalid `extends` use by duplicating inherited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex * fix(types, perf): add void return types to untyped perf methods * tests(admob): add type override to intentionally-wrong syntax Incorrect type is now caught by TS * tests(types, ml-vision): fix ml-vision test typo, exposed by proper types VisionBarcodeFormat.ALL_POINTS does not exist * chore(website): update typedoc to allow recursive types uses new syntax: TSConfigReader
It's not possible to untangle node and react-native types unfortunately, they clash. It is a known issue and apparently intractable, and new typescript projects have skipLibCheck on so we acquiesce Related #4306
It's not possible to untangle node and react-native types unfortunately, they clash. It is a known issue and apparently intractable, and new typescript projects have skipLibCheck on so we acquiesce Related #4306
…rtase#4306) * chore: enable TypeScript libcheck & remove "dom" lib "dom" conflicts with @types/react-native * chore: add react types (referenced by admob types) * refactor(types, app): move "app" exports to top-level exports, rather than module declarations with namespace extensions * refactor(types): use top-level exports for module types, rather than declarations * refactor(types): for JSON config, augment existing `ReactNativeFirebase` namespace from /app Re-exporting the namespace causes collision issues -- tramples previous values rather than merging * fix(types, admob): Use string-indexing rather than dot-notation for referring to interface keys * fix(types, analytics): convert missing interface to `any` * fix(types, database): missing `value` type (treated as 'any') * fix(types, dynamic-links): fix dynamic-links `onLink` function type "Function" is not generic * fix(types, firestore): add missing generic to Promise type Keep current behavior with `any` * fix(types, messaging): remove parameter initializer in typedef Only allowed in implementations * fix(types, messaging): avoid implicit `any` via `void` return type for `setBackgroundMessageHandler` * fix(types, ml-vision): import non-ambient types in BarcodeDetectorTypes * fix(types, ml-vision): import non-ambient types in root module from BarcodeDetectorTypes * fix(types, ml-vision): repair invalid `extends` use by duplicating inherited key Could have Omit<>'ed the incompatible `bounds` key, but duplicating the one inherited key seemed less complex * fix(types, perf): add void return types to untyped perf methods * tests(admob): add type override to intentionally-wrong syntax Incorrect type is now caught by TS * tests(types, ml-vision): fix ml-vision test typo, exposed by proper types VisionBarcodeFormat.ALL_POINTS does not exist * chore(website): update typedoc to allow recursive types uses new syntax: TSConfigReader
Related issues
Fixes #2614
Also see #2732 , #3728
Description
I ❤️
skipLibCheck: false
! The issues it catches are often non-trivial.This PR changes the following:
skipLibCheck: false
compatibilityImport declaration conflicts with local declaration of 'ReactNativeFirebase'
Exports and export assignments are not permitted in module augmentations.
Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
SetCheckoutOptionEventParameters
interface was missing, so it acted asany
.any
, rather than adding the missing interface.Approach:
Previously, module
.d.ts
files had the following:declare module '@react-native-firebase/MODULE'
with the module's exportsdeclare module '@react-native-firebase/app'
, augmenting the rootfirebase
objectnamespace ReactNativeFirebase
to augment theFirebaseJsonConfig
interface.This PR switches (1) to root-level exports, leaves (2) as-is, and merges (3) into (2) to properly merge the namespace, rather than override it.
For the type fixes, each was placed into a separate commit for easier review. Can definitely squash if desired.. there are a handful!
Checklist
Android
iOS
e2e
tests added or updated inpackages/\*\*/e2e
[No code changes]jest
tests added or updated inpackages/\*\*/__tests__
Test Plan
Type tests are passing, and one intentionally-incorrect test was updated with a type override, since TS now catches the error.
Test patches to be used with
patch-package
https://gist.github.com/davidgovea/2feea6af41b41f76fae1a9c14465cb69Thanks for reading! I know that @mikehardy has probably already read this before I submitted it.. somehow.. 🧙