Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in building app with react-hook-form using TS

I get the following error when I try to build my react app using react-hook-form in TS:

node_modules/react-hook-form/dist/types/utils.d.ts:24:77 - error TS1005: '?' expected.

24 declare type PathImpl<K extends string | number, V> = V extends Primitive ? `${K}` : `${K}` | `${K}.${Path<V>}`;
                                                                               ~~~

node_modules/react-hook-form/dist/types/utils.d.ts:24:84 - error TS1005: ';' expected.

24 declare type PathImpl<K extends string | number, V> = V extends Primitive ? `${K}` : `${K}` | `${K}.${Path<V>}`;
                                                                                      ~

node_modules/react-hook-form/dist/types/utils.d.ts:24:110 - error TS1005: '(' expected.

24 declare type PathImpl<K extends string | number, V> = V extends Primitive ? `${K}` : `${K}` | `${K}.${Path<V>}`;

And here's my build command:

yarn tsc --emitDeclarationOnly && tsc-alias -p tsconfig.json

Here's my tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "jsx": "react",
    "declaration": true,
    "outDir": "dist",
    "rootDir": "src",
    "downlevelIteration": true,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "noEmit": false,
    "baseUrl": "./src",
    "paths": {
      "@context/*": [
        "context/*"
      ],
      "@types": [
        "types/index.ts"
      ]
    }
  },
  "include": [
    "src/**/*",
  ],
  "exclude": [
    "node_modules/",
    "./src/**/*.stories.tsx",
    "./src/**/*.test.tsx",
    "./src/**/__mocks__/**/*"
  ]
}

I'm using react-hook-form version 7.6.6. Any suggestion on how to fix this would be much appreciated!

like image 521
Sabbir Ahmed Avatar asked Dec 22 '22 15:12

Sabbir Ahmed


1 Answers

According to this discussion, react-hook-form v7 needs TS 4.1 above

like image 98
nathaniaelvina Avatar answered Dec 26 '22 21:12

nathaniaelvina