Open henrixapp opened 6 years ago
Hey @henrixapp I appreciate your work and from using TypeScript myself for certain projects, I know how nice it is to have the correct types for all of your dependencies.
But what concerns me is this: the types have to be updated every time I make some changes – and to be completely honest with you: I don't want to invest my time in that. It even gets more complicated if other people decide to contribute their time, I can't expect every contributor to be familiar with TypeScript.
So I decided against adding types in this repository. I'm sorry.
But I'd be very happy if you (or anyone else) decides to invest some time and add vuex-map-fields
to https://github.com/DefinitelyTyped/DefinitelyTyped
Thx for contributing!
The other way to add v-m-f with ts is:
import Vue from "vue";
import Vuex from "vuex";
const vuexMapFields = require("vuex-map-fields");
const getField = vuexMapFields.getField;
const updateField = vuexMapFields.updateField;
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
getters: { getField },
mutations: { updateField },
actions: {},
modules: {}
});
Hey @maoberlehner !
It seems there is a simpler way to get typings in than to add them to DefinitelyTyped, which has its whole own process and standards.
Instead it is recommended by them that, if there is a way to generate these automatically, to just add them to the npm repo:
If you are the library author and your package is written in TypeScript, bundle the autogenerated declaration files in your package instead of publishing to Definitely Typed.
source: https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package
However this can also be done with JS. For generating these typings we just need to add typescript to the devDependencies and add a step in the build scripts which runs typescript with a special config. After that, the type definitions will be provided simply from within the folder node_modules/vuex-map-fields/types
instead of node_modules/@types/vuex-map-fields
, which I believe is much simpler. We just reference that folder in the package.json
All of which has been done here:
https://github.com/maoberlehner/vuex-map-fields/pull/137
The auto-generated typings are currently not really the most precise as they will just default to any
in most cases. I believe it is possible to add and precisely generate these via jsDoc somehow, which is something which would need to be done in order to serve meaningful types. That is something which has not been done in this PR yet.
This PR way however avoids needing to create a shim d.ts
to avoid errors when the vue project has been set up with typescript, so I would argue it is a step into the right direction.
Adding a
index.d.ts
would be great in order to support typescript. I have drafted one already, based on the vuex one:Probably the unused types should be removed. Currently it just enables correct typing with
createHelpers