dkfbasel / vuex-i18n

Localization plugin for vue.js 2.0 using vuex as store
MIT License
666 stars 56 forks source link

Improve typescript declarations #113

Open Shinigami92 opened 5 years ago

Shinigami92 commented 5 years ago

Currently the declarations created in #111 are not very helpful.

Maybe you can improve them and pick up the declarations from here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/vuex-i18n/index.d.ts

After that we can remove it from DefinitelyTyped

vuduongq commented 5 years ago

Hi @Shinigami92

Thanks for providing the typescript declarations. I have updated the d.ts of the package.

Shinigami92 commented 5 years ago

In which case can this.$t('something') return undefined?

https://github.com/dkfbasel/vuex-i18n/blob/2c54cea2d09cc9e7399fdb3cdf41f86bc0b05d28/dist/vuex-i18n.d.ts#L6

I thought if the key is missing, 'something' will be returned. I think it is never returning undefined.

I use strict in my projects, and after every $t call, I have to append a ! to tell TypeScript that I don't assume undefined.

Edit: Also looking into your code

https://github.com/dkfbasel/vuex-i18n/blob/67fc6b53c8a367e654a63114ca7cc2066ace1e5a/src/vuex-i18n-plugin.js#L98

The defaultValue is empty string and I think this is a good idea!

tikiatua commented 5 years ago

Version 2 of the plugin is in the works and completely written in typescript (see version 2 branch)