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
}
解决方案
出于某种原因,我不得不将每个类CreatePlanArgs
从新文件中拆分出来。
推荐阅读
- bash - 列出所有分支中比 master 上的最新标签年轻的所有标签
- amazon-web-services - Jenkins Cloudformation 插件给出 InValid Client Id 错误
- c# - 如何用 Task 输出字符串值
C#中的函数 - c++ - 用函数替换宏
- react-native - 有什么功能可以从 React Native 上传 Instagram 故事吗?
- javascript - 检查用户是否访问了页面?
- javascript - 如何在 twilio-programmable-chat 中对频道进行分页?
- javascript - 如何通过js禁用网络摄像头?
- java - 当我在上传帖子时尝试获取密钥时,我从 push() 中得到了错误的 postKey
- powershell - 需要一种使用 Powershell 针对远程服务器测试用户的方法