Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ switch noImplicitAny back on (#44)
We had to switch the `noImplicitAny` TypeScript compiler option off when [upgrading to `firebase-functions@1.0.0`](65a6108#diff-dc8de0a814a0e019ed6c1deb12c75cfeR13) because it is not compatible with it (see [this issue](firebase/firebase-functions#213)). However since then `firebase-functions` has been patched, and we've upgraded so we should be able to turn the option back on. When I tried to turn it on, the compiler detected a few places where the code was relying on some legitimate implicit anys. But it did also complain about 2 other packages that were not compatible with the option, because they were lacking types. These packages are `lodash.partition` and `firebase-tools`. I chose to remove `lodash.partition` because I felt it was not pulling its weight, as suggested by @brunosabot [here](#12 (comment)). On the other hand, we really need `firebase-tools`, but this time instead of turning `noImplicitAny` off because of it, I took the time to study how it can be left on while using packages without types. It turns out it is possible to write your own type declarations for a module installed from npm, though it took a bit of trial and error to get there. I've documented what works in `@types/README.md`, and I've written a type declaration for the one and only function that we use from the package.
- Loading branch information
Showing
9 changed files
with
51 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This the folder where we put custom type declaration files for libraries that don't come with one. | ||
|
||
File structure must be the same as in `node_modules`: | ||
- folders in this folder must be named with the name of the library (if the library is scoped then there must be a folder tree that matches the scope, e.g. `@google/firebase` gives a `@google` folder with a `firebase` folder inside) | ||
- each library folder must contain a file named `index.d.ts` with the root declaration file | ||
|
||
Please document how the types were determined. There is no need to type more than we need. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
declare module "firebase-tools" { | ||
export namespace firestore { | ||
// types inferred from https://github.com/firebase/firebase-tools/blob/v5.1.1/commands/firestore-delete.js#L72 | ||
|
||
// overload that deletes only one collection | ||
function _delete(path: string, options?: DeleteOptions): Promise<void>; | ||
|
||
// overload that deletes all collections | ||
function _delete( | ||
path: undefined, | ||
options: { allCollections: true } & DeleteOptions | ||
): Promise<void>; | ||
|
||
type DeleteOptions = { | ||
project: string; | ||
allCollections?: false; // makes no sense to have this be true if a path is provided | ||
recursive?: boolean; | ||
shallow?: boolean; | ||
yes: true; // makes no sense to have this not be true when calling from code (i.e. not from the CLI) | ||
}; | ||
|
||
// this is required because TypeScript type declarations do not support | ||
// keywords as function names | ||
export { _delete as delete }; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters