【问题标题】:Type from external module cannot be named无法命名来自外部模块的类型
【发布时间】:2020-04-05 11:27:54
【问题描述】:

我收到一个非常奇怪的打字错误,我不知道为什么会这样:

我有一个函数“cleanArgs”可以正常工作并且输入正确。但是由于某种原因,当我在类方法中使用此函数时,该方法出现错误:

导出类的公共方法的返回类型已经或正在使用来自外部模块“./project/file.ts”的名称“CreatePlanGroupArgs”,但不能命名为.ts(4053)

导出类的公共方法的返回类型已经或正在使用来自外部模块“./project/file.ts”的名称“ReadPlanGroupArgs”,但不能命名为.ts(4053)

import { CreatePlanArgs } from 'createPlan/CreatePlanArgs'
import { Helper } from 'helper/Helper'

// this is typed properly

const cleanArgs = (createPlanArgs: CreatePlanArgs) => {
  const { planGroup, ...plan } = Helper.sanitize(createPlanArgs)
  const create = Helper.sanitize(planGroup.create)
  const find = Helper.sanitize(planGroup.find)
  const pg = { create, find }
  return { planGroup: pg, plan }
}

export class Process {
  constructor (
    private readonly args: {
      createPlanArgs: CreatePlanArgs;
    }
  ) {}

  cleanArgs () { // < the error is on this line
    return cleanArgs(this.args.createPlanArgs)
  }
}

CreatePlanArgs 类看起来像这样:

@InputType()
class CreatePlanGroupArgs {
  @Field(() => String)
  name: string
}

@InputType()
class ReadPlanGroupArgs {
  @Field(() => String)
  uuid: string
}

@InputType()
class SelectPlanGroupArgs {
  @Field(() => ReadPlanGroupArgs, { nullable: true })
  find: ReadPlanGroupArgs

  @Field(() => CreatePlanGroupArgs, { nullable: true })
  create: CreatePlanGroupArgs
}

@ArgsType()
export class CreatePlanArgs {
  @Field(() => SelectPlanGroupArgs)
  planGroup: SelectPlanGroupArgs
}

【问题讨论】:

    标签: typescript


    【解决方案1】:

    出于某种原因,我不得不将 CreatePlanArgs 中的每个类分解为新文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-29
      • 2017-11-21
      • 2017-09-06
      • 2018-01-06
      • 2018-07-09
      • 2017-10-09
      • 2023-01-05
      • 2019-06-06
      相关资源
      最近更新 更多