You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Export core API typings in a namespace & use ES modules
Using ES modules (import/export everywhere) prevents from polluting the
global namespace with values and types, which is a best practice for a
GAS library.
Using a namespace for the core API typings allows for a better DX when
using the library in other GAS projects.
Use it like this:
1. Install the library just for grabbing its types locally:
npm -i -D firestore_google-apps-script # once/if published to npmjs.com
# or
npm -i -D grahamearley/FirestoreGoogleAppsScript # in the meantime
2. In a .d.ts file of your making that’s included in tsconfig.json, add:
import { FirestoreGoogleAppsScript } from "firestore_google-apps-script/typings";
declare const FirestoreDataSource: FirestoreGoogleAppsScript.FirestoreApp; // globally available
// or
declare global { const FirestoreDataSource: FirestoreGoogleAppsScript.FirestoreApp; } // globally available
// or
export const FirestoreDataSource: FirestoreGoogleAppsScript.FirestoreApp; // you’ll have to import it in files
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 the `userSymbol` 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 called `FirestoreApp` by default,
which does not conflict with the one that’s namespaced.
0 commit comments