TypeScript 调试失败,错误表达式,

5fjcxozz  于 4个月前  发布在  TypeScript
关注(0)|答案(3)|浏览(50)

致谢

  • 我承认,使用此模板的问题可能会在维护者的酌情决定下不经进一步解释而关闭。

评论

我不知道这个错误是如何发生的,但每当我打开这个特定的点文件时,错误信息就会出现。

Error: tsserver: 1: <semantic> TypeScript Server Error (5.2.2)
Debug Failure. False expression.
Error: Debug Failure. False expression.
    at first (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:3063:9)
    at getArgumentArityError (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75247:19)
    at resolveCall (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75464:27)
    at resolveCallExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75772:12)
    at resolveSignature (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:76155:16)
    at getResolvedSignature (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:76175:18)
    at checkCallExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:76287:23)
    at checkExpressionWorker (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:79464:16)
    at checkExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:79375:32)
    at checkExpressionWithContextualType (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:79024:18)
    at inferTypeArguments (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:74738:27)
    at inferSignatureInstantiationForOverloadFailure (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75678:31)
    at pickLongestCandidateSignature (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75657:168)
    at getCandidateForOverloadFailure (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75599:109)
    at resolveCall (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75357:14)
    at resolveCallExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:75772:12)
    at resolveSignature (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:76155:16)
    at getResolvedSignature (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:76175:18)
    at getResolvedSignatureWorker (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:48231:34)
    at /Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:47992:135
    at runWithoutResolvedSignatureCaching (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:48201:20)
    at Object.getResolvedSignatureForSignatureHelp (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:47992:88)
    at visitCallOrNewExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164835:31)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164749:7)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInAwaitExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30275:12)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInExpressionStatement (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30313:12)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInBlock (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30560:10)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInIfStatement (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30316:51)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInBlock (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30560:10)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInArrowFunction (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30183:243)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInCallOrNewExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30557:99)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInAwaitExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30275:12)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInExpressionStatement (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30313:12)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInBlock (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30560:10)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNode2 (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30083:18)
    at forEachChildInMethodDeclaration (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30162:354)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInClassDeclarationOrExpression (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30566:195)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at visitNodes (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30091:22)
    at forEachChildInSourceFile (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30304:12)
    at forEachChild (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:30600:35)
    at visitor (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164758:12)
    at Object.provideInlayHints (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:164719:3)
    at Object.provideInlayHints2 [as provideInlayHints] (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:144858:34)
    at IpcIOSession.provideInlayHints (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:183663:48)
    at provideInlayHints (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:182825:43)
    at /Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:184838:69
    at IpcIOSession.executeWithRequestId (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:184830:14)
    at IpcIOSession.executeCommand (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:184838:29)
    at IpcIOSession.onMessage (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:184880:51)
    at process.<anonymous> (/Users/innei/git/innei-repo/MetaMuse/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/lib/tsserver.js:186461:14)
    at process.emit (node:events:514:28)
    at emit (node:internal/child_process:937:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

每次我用源代码打开这个文件时:

import { BizException } from '@core/common/exceptions/biz.exception'
import { BusinessEvents } from '@core/constants/business-event.constant'
import { ErrorCodeEnum } from '@core/constants/error-code.constant'
import { DatabaseService } from '@core/processors/database/database.service'
import { EventManagerService } from '@core/processors/helper/helper.event.service'
import { resourceNotFoundWrapper } from '@core/shared/utils/prisma.util'
import { isDefined } from '@core/shared/utils/validator.util'
import { Injectable } from '@nestjs/common'
import { Post, Prisma } from '@prisma/client'

import { PostDto, PostPagerDto, PostPatchDto } from './post.dto'
import { PostIncluded } from './post.protect'

@Injectable()
export class PostService {
  constructor(
    private readonly db: DatabaseService,
    private readonly eventService: EventManagerService,
  ) {}

  async create(dto: PostDto) {
    const { slug, categoryId } = dto
    const exist = await this.db.prisma.post.findUnique({
      where: {
        slug_categoryId: {
          slug,
          categoryId,
        },
      },
      select: { id: true },
    })

    if (exist) {
      throw new BizException(ErrorCodeEnum.PostExist)
    }

    const model = await this.db.prisma.$transaction(async (prisma) => {
      const hasCategory = await this.db.prisma.category.exists({
        where: {
          id: categoryId,
        },
      })
      if (!hasCategory) {
        throw new BizException(ErrorCodeEnum.CategoryNotFound)
      }

      const newPost = await prisma.post.create({
        data: {
          ...dto,
          related: { connect: dto.related?.map((id) => ({ id })) } || [],
        },
        include: {
          category: true,
        },
      })

      return newPost
    })

    if (dto.related?.length) {
      await this.relateEachOther(model.id, dto.related)
    }

    if (model.pin) {
      await this.togglePin(model.id, true)
    }

    this.eventService.event(BusinessEvents.POST_CREATE, model)

    return model
  }

  private async relateEachOther(postId: string, relatedIds: string[]) {
    await this.db.prisma.$transaction(
      relatedIds.map((id) =>
        this.db.prisma.post.update({
          where: {
            id,
          },
          data: {
            related: {
              connect: {
                id: postId,
              },
            },
          },
        }),
      ),
    )
  }

  private togglePin(id: string, pin: boolean) {
    if (!pin) {
      return this.db.prisma.post.update({
        where: {
          id,
        },
        data: {
          pin: false,
        },
      })
    }
    return this.db.prisma.$transaction([
      this.db.prisma.post.update({
        where: {
          id,
        },
        data: {
          pin: true,
        },
      }),

      this.db.prisma.post.updateMany({
        where: {
          NOT: { id },
        },
        data: { pin: false },
      }),
    ])
  }

  async paginatePosts(
    options: PostPagerDto,
    filter: Prisma.PostWhereInput = {},
  ) {
    const {
      select,
      size = 10,
      page = 1,
      sortBy = 'created',
      sortOrder = -1,
    } = options
    const nextSortOrder = {
      ['-1']: 'desc',
      [1]: 'asc',
    }[sortOrder.toString()]

    const data = await this.db.prisma.post.paginate(
      {
        include: PostIncluded,
        where: filter,

        orderBy: [
          {
            pin: 'desc',
          },
          {
            [sortBy]: nextSortOrder,
          },
        ],
      },
      {
        size,
        page,
      },
    )

    if (select?.length) {
      const nextData = [] as typeof data.data
      for (const item of data.data) {
        if (!item) continue
        const currentItem = {} as any
        for (const key of select) {
          currentItem[key] = item[key]
        }
        nextData.push(currentItem)
      }

      data.data = nextData
    }

    return data
  }

  async getLastPost() {
    return this.db.prisma.post.findFirst({
      orderBy: {
        created: 'desc',
      },
      include: PostIncluded,
    })
  }

  async getPostById(id: string) {
    return this.db.prisma.post
      .findUniqueOrThrow({
        where: {
          id,
        },
        include: PostIncluded,
      })
      .catch(
        resourceNotFoundWrapper(new BizException(ErrorCodeEnum.PostNotFound)),
      )
  }

  async getCategoryBySlug(slug: string) {
    return this.db.prisma.category.findUnique({ where: { slug } })
  }

  async getPostBySlug(slug: string, categorySlug: string) {
    const category = await this.getCategoryBySlug(categorySlug)
    if (!category) {
      throw new BizException(ErrorCodeEnum.CategoryNotFound)
    }

    return this.db.prisma.post.findUnique({
      where: {
        slug_categoryId: {
          slug,
          categoryId: category.id,
        },
      },
      include: PostIncluded,
    })
  }

  async updateById(id: string, data: PostPatchDto) {
    await this.db.prisma.$transaction(async (prisma) => {
      const originPost = await prisma.post.findUnique({
        where: { id },
        select: {
          categoryId: true,
          modified: true,
        },
      })

      if (!originPost) {
        throw new BizException(ErrorCodeEnum.PostNotFound)
      }

      const { categoryId } = data

      if (categoryId && categoryId !== originPost.categoryId) {
        await prisma.category
          .findUniqueOrThrow({
            where: {
              id: categoryId,
            },
          })
          .catch(
            resourceNotFoundWrapper(
              new BizException(ErrorCodeEnum.CategoryNotFound),
            ),
          )
      }

      const updatedData: Partial<Post> = {
        ...data,
      }

      // @ts-expect-error
      delete updatedData.related

      if ([data.text, data.title, data.slug].some((i) => isDefined(i))) {
        const now = new Date()

        updatedData.modified = now
      }

      await prisma.post.update({
        where: {
          id,
        },
        data: updatedData,
      })
    })

    // 有关联文章
    const related = data.related?.filter((i) => i !== id) || []
    if (related.length) {
      await this.relateEachOther(id, related)
    }
  }
}
blmhpbnm

blmhpbnm1#

你能将这个隔离在某个独立的仓库或TS playground中吗?

ezykj2lf

ezykj2lf2#

你能将这个隔离在某个独立的仓库或TS playground中吗?我不知道如何最小化地复现它。目前,我能确认的是,每当我打开这个指定的文件时,就会发生错误。

lvmkulzt

lvmkulzt3#

你可以尝试二分法来重建这个项目,使用你减少的部分。首先从这个文件中删除一些函数/行,观察问题是否消失。在问题消失之前恢复刚刚删除的内容,并尝试删除文件的其他部分-重复这个过程,直到你尽可能地减少了这个问题。同样的处理过程也可以应用于这个文件的依赖项(你在它里面引用的所有导入)。

相关问题