typescript 类型“APIRequest”上不存在剧作家“Property”get“

hwamh0ep  于 2023-10-22  发布在  TypeScript
关注(0)|答案(1)|浏览(109)

所以下面的代码在test.spec.ts中对我有效:

//@ts-check
import { test, request } from '@playwright/test'

test('api test - to see if Playwright API calls are working', async ({ request }) => {
  const response = await request.get(`https://catfact.ninja/fact`);
  const statusCode = response.status()
  const responseBody = JSON.parse(await response.text())
)}

所以我想在一个单独的模块中提取这个调用。我试着在单独的文件:

import { request } from '@playwright/test';

export async function getCatInfo() {
    const response = await request.get(`https://catfact.ninja/fact`)
}

在VS代码中出现错误:Property 'get' does not exist on type 'APIRequest'
我做错了什么?

omqzjyyz

omqzjyyz1#

您应该从playwright/test导入:

import { test, request } from '@playwright/test';

export async function getCatInfo() {
    const response = await request.get(`https://catfact.ninja/fact`)
}

相关问题