Export relevant types in a namespace for local TypeScript development #174
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.
(Kinda) Fixes #131.
Recap: the issue at stake is that right now, it’s impossible to grab the library’s types to please TypeScript’s type checker, for the repository is merely a group of .ts files, eventually projecting conflict-prone JS values in the global namespace.
Solution: Use ES modules (import/export everywhere) to prevent from polluting the global namespace with values and types, which is a best practice for a GAS library; and rework index.d.ts to properly expose the library’s types through a dedicated namespace, the same way the OAuth 2 library does it (from the guys at Google).
How to then use the library for TypeScript developpment:
Note: although you don’t need to, it may clarify your intent adding:
/// <reference types="../node_modules/firestore_google-apps-script/typings/index.d.ts" />
Note: you may rename
FirestoreDataSource
, it’s just a Clean Architecture naming convention I’m following, which maps theuserSymbol
I dediced to use in appsscript.json. If you are manually enabling the lib through the Google Apps Script UI, it will actually be be calledFirestoreApp
by default, which does not conflict with the one that’s namespaced.