Open callumlocke opened 4 years ago
@callumlocke thanks for this, seems like a totally reasonable request to make. I am not JavaScriptSmartEnough to implement it, but I imagine @bkendall has thought about this before.
One difficulty is probably that most of the commands are defined at runtime, so we'd have to do some fancy logic to generate the .d.ts
file.
ditto. Why isn't this high priority?
This is something I've been toying with recently, but there are other priorities out there and, unfortunately, I'm not sure how useful automatically generated types would be. Our typing has gotten somewhat better as of late in the codebase, but I'm not sure it's ready for 'external' primetime.
Thanks for showing interest though - it does help to prioritize work! :)
I want
I'm also skeptical of the utility provided by automatically generated types for this package, but one particular use case that I think would be valuable is exposing FirebaseConfig
, either directly from firebase-tools
or from a separate package.
I needed access to that type in order to build a tool for managing Firebase config files. I considered using json-schema-to-typescript
to consume the config schema available in this package, but it seemed a bit silly to generate TypeScript from a schema file that was itself generated from TypeScript, so for now I'm directly copying firebaseConfig.ts
into my package.
@jakekrog we have recently started building a JSON Schema for that file: https://github.com/firebase/firebase-tools/blob/master/schema/firebase-config.json
You can probably make some use of that! We have not yet hosted the schema anywhere, but you can grab it from GitHub at that predictable location for now.
@samtstern thanks for the quick response! I did try using that schema with json-schema-to-typescript
to essentially recreate firebaseConfig.ts
, but the generated TypeScript is more convoluted and missing granular type definitions.
You can see the difference by comparing the original firebaseConfig.ts to what is generated from json-schema-to-typescript
.
I do feel a bit icky copying firebaseConfig.ts
directly into the package I'm working on, but certainly less icky than using a schema generated from TypeScript to recreate an approximation of types not yet exported from this package. The 'Advanced' example from the package I linked above would not be possible without those type definitions:
// firebase.config.ts
import {
EmulatorsConfig,
FirebaseConfig,
FirestoreConfig,
FunctionsConfig,
StorageConfig,
generateFirebaseConfig,
} from '@mandalify/firebase-config-generator'
const AUTH_EMULATOR_PORT = 9099
const FIRESTORE_EMULATOR_PORT = 8080
const FUNCTIONS_EMULATOR_PORT = 5001
function emulatorsConfig(host: string, uiEnabled: boolean): EmulatorsConfig {
return {
auth: {host, port: AUTH_EMULATOR_PORT},
functions: {host, port: FUNCTIONS_EMULATOR_PORT},
firestore: {host, port: FIRESTORE_EMULATOR_PORT},
ui: {enabled: uiEnabled}
}
}
const firestore: FirestoreConfig = {
rules: 'firestore.rules',
indexes: 'firestore.indexes.json',
}
const functions: FunctionsConfig = {
source: 'functions',
}
const storage: StorageConfig = {
rules: 'storage.rules',
}
const baseConfig: FirebaseConfig = {
firestore,
functions,
storage,
}
generateFirebaseConfig({
// 'default' writes to firebase.json
default: {
...baseConfig,
functions: {
...functions,
predeploy: [
"npm --prefix functions install",
"npm --prefix functions run lint",
"npm --prefix functions run build"
]
},
emulators: emulatorsConfig('0.0.0.0', true),
},
// arbitrary keys write to firebase.{key}.json
githhub: {
...baseConfig,
emulators: emulatorsConfig('localhost', false),
}
})
Any update on this? Adding this would make using firebase-tools in a typescript environment much easier. Given that all other official firebase projects I've used seem to have basic Typescript support, I'm not sure why this one is lacking it.
I would love to see this and would be more than happy to help out if needed. I want to use the firebase-tools package inside other code and typings would go a loooong way.
👍
[REQUIRED] Environment info
firebase-tools: 8.4.3
Platform: macOS Catalina
[REQUIRED] Test case
or
[REQUIRED] Steps to reproduce
Just import the 'firebase-tools' module in a TypeScript file and run
tsc
on it.[REQUIRED] Expected behavior
It should come with its own types (it is written in TypeScript, after all).
[REQUIRED] Actual behavior
TypeScript complains that this module has no type declations:
Sure enough, looking at the actual published package in my
node_modules
, it contains no.d.ts
files. Why?There's also nothing at
@types/firebase-tools
.