"Yup" 验证库无法在 TypeScript 中编译

"Yup" Validation Library fails to compile in TypeScript

所以我转而使用 Yup 库在我的项目上进行表单验证,但是当我安装它时(并在之后尝试了很多次)我一直遇到这个非常奇怪的库错误。

我完全不知道如何克服这个问题。任何帮助将不胜感激。


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';

是的,项目的版本 0.32.8 使用 TypeScript 版本 v4.0.5

自 TypeScript v3.8

以来支持编译器抱怨的功能 import type

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 };

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