vuejs-logger: Property '$log' does not exist on type '*'
Hi!
I’m using TypeScript with my Vue 2 project but after adding the vuejs-logger module and bound it to Vue I get the following error:
Property '$log' does not exist on type 'Application'.
That’s the same for all my components… any idea how to solve this please?
Thanks
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (4 by maintainers)
@sneko solution almost worked for me. Had to change the interface to use the
VueConstructorinstead.@justinkames would you consider adding such a
.d.tsfile in the NPM package, or publishing another package with type definitions? This is needed to properly use vuejs-logger in Typescript projects.In the meantime we can all work around it by adding the definitions ourselves, but it would be better if we didn’t have to.
The info comes from here: https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins
I forgot to include that you have to
import Vueso the whole file looks like:If you’re using VSCode you might have to reload the window for it to pick up the declaration file.
I should also mention that I’ve stopped using vuejs-logger, so this declaration file is not complete. At a glance it’s missing the
debugandfatalmethods, but also bear in mind that the log levels appear to be configurable, so you might need some dynamic typings.The d.ts file is now included in version 1.5.4 and ( 0964b185c6a92f234314b4bbcf83c8ac68ab155c )
Adding this here in case others find it useful. I actually fixed it by doing the following:
My understanding (I’m new to Typescript) is that you want to declare the module for the, well, module you installed, here
vue-jsloggerand in it extend existing modules (the Vue onevue/types/vueshould be installed already if you’re reading this) with the correct interface so that vscode understands it. For instance the above does the trick if you’re calling $log from theVueinstance directly by upgrading its constructor. If you’re calling from within a Vue instance, add the declaration to theVueinterface directly.No worries, glad it’s working 😃
It was simply that our requirements changed - we need to post our logs to an API. I ended up creating my own very simple Plugin - I’m very grateful to @justinkames for his work with this because it is great to learn from. In the end we just needed something a bit more specific to our needs.
@sneko I solved this by extending the vue model myself
I realise this is only a short term solution, but just in case you needed something immediately.