diff --git a/.eslintrc b/.eslintrc index bee50275..733025f0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,5 +11,6 @@ "extends": "@avalanche/eslint-config", "rules": { "compat/compat": "error" - } + }, + "ignorePatterns": ["**/*.d.ts"] } diff --git a/package.json b/package.json index b800317f..ae561859 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "scripts:umd": "rollup --config --output.format umd --name vuex-map-fields --output.file dist/index.js src/index.js", "scripts:es": "rollup --config --output.format es --name vuex-map-fields --output.file dist/index.esm.js src/index.js", "scripts:minify": "uglifyjs --compress --mangle --comments --output dist/index.min.js dist/index.js && uglifyjs --compress --mangle --comments --output dist/index.esm.min.js dist/index.esm.js", - "scripts": "yarn run scripts:umd && yarn run scripts:es && yarn run scripts:minify", + "scripts:typing": "tsc --project tsconfig.build-types.json", + "scripts": "yarn run scripts:umd && yarn run scripts:es && yarn run scripts:minify && yarn run scripts:typing", "build": "yarn run scripts", "fake-publish": "yarn run build && sh test/utils/fake-publish.sh", "lint:scripts": "yarn run fake-publish && eslint --ignore-path .gitignore .", @@ -42,12 +43,14 @@ "jest": "^26.4.2", "rollup": "^2.28.2", "rollup-plugin-babel": "^4.4.0", + "typescript": "^4.2.4", "uglify-es": "^3.3.9", "vue": "^2.6.12", "vue-template-compiler": "^2.6.12", "vuex": "^3.5.1" }, "main": "dist/index.js", + "types": "types/vuex-map-fields/index.d.ts", "module": "dist/index.esm.js", "repository": { "type": "git", diff --git a/tsconfig.build-types.json b/tsconfig.build-types.json new file mode 100644 index 00000000..11da3bc4 --- /dev/null +++ b/tsconfig.build-types.json @@ -0,0 +1,10 @@ +{ + "include": ["src/**/*"], + "exclude": ["src/**/*.spec.js"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "types/vuex-map-fields" + } +} diff --git a/types/vuex-map-fields/index.d.ts b/types/vuex-map-fields/index.d.ts new file mode 100644 index 00000000..cec16091 --- /dev/null +++ b/types/vuex-map-fields/index.d.ts @@ -0,0 +1,15 @@ +export function getField(state: any): (path: any) => any; +export function updateField(state: any, { path, value }: { + path: any; + value: any; +}): void; +export function mapFields(...params: any[]): any; +export function mapMultiRowFields(...params: any[]): any; +export function createHelpers({ getterType, mutationType }: { + getterType: any; + mutationType: any; +}): { + [x: number]: typeof updateField; + mapFields: (...params: any[]) => any; + mapMultiRowFields: (...params: any[]) => any; +}; diff --git a/types/vuex-map-fields/lib/array-to-object.d.ts b/types/vuex-map-fields/lib/array-to-object.d.ts new file mode 100644 index 00000000..646d923b --- /dev/null +++ b/types/vuex-map-fields/lib/array-to-object.d.ts @@ -0,0 +1 @@ +export default function arrayToObject(fields?: any[]): any; diff --git a/yarn.lock b/yarn.lock index 3bdfc67e..58e263c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5093,6 +5093,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.2.4: + version "4.2.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961" + integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg== + uglify-es@^3.3.9: version "3.3.9" resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"