Search code examples
reactjstypescriptformikyup

"Yup" Validation Library fails to compile in TypeScript


I have been turned to using the Yup library for form validation on my project however when I have installed it (and tried many many more times after that) I have been encountering this extremely odd library error consistently.

How can I get past this?

Failed to compile.

C:/Users/x/Documents/y/frontend/node_modules/yup/lib/array.d.ts
TypeScript error in C:/Users/x/Documents/y/frontend/node_modules/yup/lib/array.d.ts(2,13):
'=' expected.  TS1005

    1 | import { MixedLocale } from './locale';
  > 2 | import type { AnyObject, InternalOptions, Callback, Message, Maybe, Preserve, Optionals } from './types';
      |             ^
    3 | import type Reference from './Reference';
    4 | import { Asserts, Defined, If, Thunk, TypeOf } from './util/types';
    5 | import BaseSchema, { AnySchema, SchemaInnerTypeDescription, SchemaSpec } from './schema';

Solution

  • Yup project's verison 0.32.8 uses TypeScript version v4.0.5.

    Feature import type which compiler complains is supported since TypeScript v3.8

    This feature is something most users may never have to think about; however, if you’ve hit issues under --isolatedModules, TypeScript’s transpileModule API, or Babel, this feature might be relevant.

    import type { SomeThing } from "./some-module.js";
    export type { SomeThing };
    

    source: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html