【问题标题】:Turn off TS4023 typescript error: external module "xyz" but cannot be named关闭 TS4023 typescript 错误:外部模块 \"xyz\" 但无法命名
【发布时间】:2023-01-05 15:29:26
【问题描述】:
//feature1.slice.ts

import { createGenericSlice } from '@me/data-rtk';

/* ***********************For Storing all the divisions data****************************** */
export const divisionDataSlice = createGenericSlice({
  name: 'divisiondata',
  initialState: { status: 'loading' },
} )({
  setDivisionData(state, { payload }) {
    state.data = payload;
  },
});


/**************------------------*******************************/


//@me/data-rtk File
interface GenericState<T> {
  data?: T;
  status: 'loading' | 'finished' | 'error';
}

type Obj = Record<string, any>;

export const createGenericSlice = <D extends Obj, T extends Obj>({
  name = '',
  initialState,
}: {
  name: string;
  initialState: GenericState<T>;
}) = {return //Reducers}

我上面的代码返回以下错误。是否有标志/配置来关闭此类错误。

Error during bundle: Error: feature1.slice.ts(4, 14): semantic error TS4023: Exported variable 'divisionDataSlice' has or is using name 'GenericState' from external module "rtk-slice" but cannot be named.

我已经通过 tsConfig 可能的选项并尝试过,但没有用。

如果没有办法关闭这个错误,有没有办法从代码中修复这个错误。

【问题讨论】:

  • 启用skipLibCheck 这样 TS 就不会检查您正在使用的库。
  • @维拉。我看到标志 skipLibCheck 已经启用,但仍然看到这个错误

标签: typescript


【解决方案1】:

我能够通过将分配的类型设置为 any 来绕过错误。 export const divisionDataSlice**: any** = createGenericSlice({}) 复制代码

由于选择退出静态类型,编译器不需要计算出 divisionDataSlice 的形状。

【讨论】:

    猜你喜欢
    • 2018-01-06
    • 2017-10-09
    • 2015-01-07
    • 2020-04-05
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2019-03-29
    • 2014-05-27
    相关资源
    最近更新 更多