Typing custom plugin #11028
Unanswered
mrc-bsllt
asked this question in
Help/Questions
Replies: 2 comments
-
You can write a composable for this: import { inject } from 'vue'
export function useMondayApiClient() {
return inject<ApiClient>('mondayClient');
} <script setup lang="ts">
import { onMounted, inject } from 'vue'
import { useMondayApiClient } from '...'
const mondayClient = useMondayApiClient()
onMounted(async () => {
const me = await mondayClient.operations.getMeOp()
console.log('me', me)
})
</script>
<template>
<main></main>
</template> |
Beta Was this translation helpful? Give feedback.
0 replies
-
For anyone looking here, the best practice is according to the docs is to use the import type { App } from 'vue'
import { ApiClient } from '@mondaydotcomorg/api'
interface MondayOptions {
apiKey: string
}
export default {
install: (app: App, options?: MondayOptions) => {
const apiKey = options?.apiKey || import.meta.env.VITE_MONDAY_API_KEY
const client = new ApiClient(apiKey)
const key = Symbol(''mondayClient") as InjectionKey<typeof client>
app.provide(key , client)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone! I have created a custom plugin and through provide/inject I call it up in my components, but I cannot get it to remain typecast.
plugin.ts
main.ts
App.vue
I know I could add the type to inject const
mondayClient = inject<ApiClient>('mondayClient')
, but I would like not to have to do this in all the components where I have imported it.Beta Was this translation helpful? Give feedback.
All reactions