无法命名来自外部模块的类型

时间:2019-12-12 05:42:13

标签: typescript

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

我有一个函数“ 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
}

1 个答案:

答案 0 :(得分:0)

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

相关问题