Skip to content

Commit

Permalink
Remove errors from Typescript usage (react-hook-form#54)
Browse files Browse the repository at this point in the history
* Remove errors from Typescript usage
- Disable non-critical eslint rules
- Add react rules for eslint
- Update ts-eslint parser to fix latest bugs
- Minor changes to fix bugs and avoid variable check errors

* Correct location of eslint plugin add
  • Loading branch information
barrymay authored and bluebill1049 committed Jun 5, 2019
1 parent f294dca commit 47e5783
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 27 deletions.
18 changes: 12 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended'],
parser: "@typescript-eslint/parser",
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
sourceType: "module"
},
rules: {
'@typescript-eslint/indent': 'off',
'@typescript-eslint/no-non-null-assertion': 'off'
},
"@typescript-eslint/indent": "off",
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'react/prop-types': 'off'
}
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"@types/jest": "^24.0.11",
"@types/react": "^16.8.13",
"@types/react-test-renderer": "^16.8.1",
"@typescript-eslint/eslint-plugin": "^1.7.0",
"@typescript-eslint/parser": "^1.7.0",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"coveralls": "^3.0.3",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.12.1",
"eslint": "^5.16.0",
"eslint-plugin-react": "^7.13.0",
"jest": "^24.7.1",
"npm-run-all": "^4.1.5",
"react": "^16.8.6",
Expand Down
6 changes: 5 additions & 1 deletion src/logic/getFieldValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import isCheckBox from '../utils/isCheckBoxInput';

export default function getFieldValue<Data extends DataType>(fields: FieldsObject<Data>, { type, name, options, checked, value }: Ref): FieldValue {
if (isRadioInput(type)) {
return getRadioValue(fields[name]!.options).value;
let fieldValue = fields[name];
if (fieldValue === undefined) {
throw new Error(`Expected Field Value for ${name}`)
}
return getRadioValue(fieldValue.options).value;
}

if (type === 'select-multiple') return getMultipleSelectValue(options);
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react",
"module": "commonjs"
"module": "commonjs",
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"declaration": true,
"strictNullChecks": true,
"jsx": "react",
"skipLibCheck": true
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
},
"include": ["src"],
"exclude": ["node_modules", "test", "examples"]
Expand Down
81 changes: 66 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -419,31 +419,40 @@
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.9.tgz#693e76a52f61a2f1e7fb48c0eef167b95ea4ffd0"
integrity sha512-sCZy4SxP9rN2w30Hlmg5dtdRwgYQfYRiLo9usw8X9cxlf+H4FqM1xX7+sNH7NNKVdbXMJWqva7iyy+fxh/V7fA==

"@typescript-eslint/eslint-plugin@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.7.0.tgz#570e45dc84fb97852e363f1e00f47e604a0b8bcc"
integrity sha512-NUSz1aTlIzzTjFFVFyzrbo8oFjHg3K/M9MzYByqbMCxeFdErhLAcGITVfXzSz+Yvp5OOpMu3HkIttB0NyKl54Q==
"@typescript-eslint/eslint-plugin@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.9.0.tgz#29d73006811bf2563b88891ceeff1c5ea9c8d9c6"
integrity sha512-FOgfBorxjlBGpDIw+0LaZIXRX6GEEUfzj8LXwaQIUCp+gDOvkI+1WgugJ7SmWiISqK9Vj5r8S7NDKO/LB+6X9A==
dependencies:
"@typescript-eslint/parser" "1.7.0"
"@typescript-eslint/typescript-estree" "1.7.0"
"@typescript-eslint/experimental-utils" "1.9.0"
"@typescript-eslint/parser" "1.9.0"
eslint-utils "^1.3.1"
functional-red-black-tree "^1.0.1"
regexpp "^2.0.1"
requireindex "^1.2.0"
tsutils "^3.7.0"

"@typescript-eslint/[email protected]", "@typescript-eslint/parser@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.7.0.tgz#c3ea0d158349ceefbb6da95b5b09924b75357851"
integrity sha512-1QFKxs2V940372srm12ovSE683afqc1jB6zF/f8iKhgLz1yoSjYeGHipasao33VXKI+0a/ob9okeogGdKGvvlg==
"@typescript-eslint/[email protected]":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.0.tgz#a92777d0c92d7bc8627abd7cdb06cdbcaf2b39e8"
integrity sha512-1s2dY9XxBwtS9IlSnRIlzqILPyeMly5tz1bfAmQ84Ul687xBBve5YsH5A5EKeIcGurYYqY2w6RkHETXIwnwV0A==
dependencies:
"@typescript-eslint/typescript-estree" "1.9.0"

"@typescript-eslint/[email protected]", "@typescript-eslint/parser@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.9.0.tgz#5796cbfcb9a3a5757aeb671c1ac88d7a94a95962"
integrity sha512-CWgC1XrQ34H/+LwAU7vY5xteZDkNqeAkeidEpJnJgkKu0yqQ3ZhQ7S+dI6MX4vmmM1TKRbOrKuXc6W0fIHhdbA==
dependencies:
"@typescript-eslint/typescript-estree" "1.7.0"
"@typescript-eslint/experimental-utils" "1.9.0"
"@typescript-eslint/typescript-estree" "1.9.0"
eslint-scope "^4.0.0"
eslint-visitor-keys "^1.0.0"

"@typescript-eslint/typescript-estree@1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.7.0.tgz#59ec02f5371964da1cc679dba7b878a417bc8c60"
integrity sha512-K5uedUxVmlYrVkFbyV3htDipvLqTE3QMOUQEHYJaKtgzxj6r7c5Ca/DG1tGgFxX+fsbi9nDIrf4arq7Ib7H/Yw==
"@typescript-eslint/typescript-estree@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.0.tgz#5d6d49be936e96fb0f859673480f89b070a5dd9b"
integrity sha512-7Eg0TEQpCkTsEwsl1lIzd6i7L3pJLQFWesV08dS87bNz0NeSjbL78gNAP1xCKaCejkds4PhpLnZkaAjx9SU8OA==
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"
Expand Down Expand Up @@ -629,6 +638,14 @@ array-filter@~0.0.0:
resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec"
integrity sha1-fajPLiZijtcygDWB/SH2fKzS7uw=

array-includes@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.0.3.tgz#184b48f62d92d7452bb31b323165c7f8bd02266d"
integrity sha1-GEtI9i2S10UrsxsyMWXH+L0CJm0=
dependencies:
define-properties "^1.1.2"
es-abstract "^1.7.0"

array-map@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662"
Expand Down Expand Up @@ -1216,6 +1233,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a"
integrity sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=

doctrine@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
integrity sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==
dependencies:
esutils "^2.0.2"

doctrine@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
Expand Down Expand Up @@ -1393,6 +1417,19 @@ escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"

eslint-plugin-react@^7.13.0:
version "7.13.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.13.0.tgz#bc13fd7101de67996ea51b33873cd9dc2b7e5758"
integrity sha512-uA5LrHylu8lW/eAH3bEQe9YdzpPaFd9yAJTwTi/i/BKTD7j6aQMKVAdGM/ML72zD6womuSK7EiGtMKuK06lWjQ==
dependencies:
array-includes "^3.0.3"
doctrine "^2.1.0"
has "^1.0.3"
jsx-ast-utils "^2.1.0"
object.fromentries "^2.0.0"
prop-types "^15.7.2"
resolve "^1.10.1"

eslint-scope@^4.0.0, eslint-scope@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
Expand Down Expand Up @@ -2799,6 +2836,13 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

jsx-ast-utils@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.1.0.tgz#0ee4e2c971fb9601c67b5641b71be80faecf0b36"
integrity sha512-yDGDG2DS4JcqhA6blsuYbtsT09xL8AoLuUR2Gb5exrw7UEM19sBcOTq+YBBhrNbl0PUC4R4LnFu+dHg2HKeVvA==
dependencies:
array-includes "^3.0.3"

kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
Expand Down Expand Up @@ -3915,6 +3959,13 @@ [email protected]:
dependencies:
path-parse "^1.0.6"

resolve@^1.10.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.1.tgz#ea10d8110376982fef578df8fc30b9ac30a07a3e"
integrity sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==
dependencies:
path-parse "^1.0.6"

restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
Expand Down

0 comments on commit 47e5783

Please sign in to comment.