question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Published package is missing type declarations

See original GitHub issue

[REQUIRED] Environment info

firebase-tools: 8.4.3

Platform: macOS Catalina

[REQUIRED] Test case

import * as firebaseTools from 'firebase-tools'

or

import firebaseTools from 'firebase-tools'

[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:

Could not find a declaration file for module 'firebase-tools'. '<REDACTED>/node_modules/firebase-tools/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/firebase-tools` if it exists or add a new declaration (.d.ts) file containing `declare module 'firebase-tools';`

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:31
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sgehrmancommented, Jan 28, 2021

ditto. Why isn’t this high priority?

0reactions
jakekrogcommented, Jul 29, 2021

@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),
    }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Declare Missing Types for External Libraries -- newline
Custom Types Declaration#. First, in your tsconfig.json add a directory path to type declarations:.
Read more >
Missing type definition information in VS Code when own ...
Missing type definitions when referencing the published package: import { CrmRpc} from "efficy-enterprise-api"; const crm = new ...
Read more >
Documentation - Publishing - TypeScript
There are two main ways you can publish your declaration files to npm: bundling with your npm package; publishing to the @types organization...
Read more >
A Complete Guide to Using TypeScript in Node.js - Better Stack
Fixing errors caused by missing types. Setting up linting and formatting for TypeScript files. Debugging TypeScript in Chrome or VS Code.
Read more >
A quick introduction to “Type Declaration” files and adding ...
The DefinitelyTyped community writes declaration packages for such third-party libraries and platforms. These declaration packages are published ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found