Skip to content

How to handle types for injected properties in Vue Composition API - Typescript #2296

@harrytran998

Description

@harrytran998

What problem does this feature solve?

import firebase from 'firebase'
import Vue from 'vue'

/* This file simply imports the needed types from firebase and forwards them */
declare module 'vue/types/vue' {
  interface Vue {
    $fireStore: firebase.firestore.Firestore
    $fireDb: firebase.database.Database
    $fireFunc: firebase.functions.Functions
    $fireStorage: firebase.storage.Storage
    $fireAuth: firebase.auth.Auth
    $fireMess: firebase.messaging.Messaging
  }
}

In a normal typescript project with Vue 2, we can do like above to access this.$fireStore. But when use Composition API, how I can inject the properties like this in the root on function setup(_, { root})? So I cant use with root.$fireStore...

Now, I must use it with any type like (root as any).$fireStore. So hope anyone can help my team. We are working on a project with Nuxt Composition now.

What does the proposed API look like?

setup(_, { root}) {
 root.$xyz 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions