【发布时间】:2022-01-21 14:29:41
【问题描述】:
导致问题的代码是下面的代码
import {Client, LogLevel} from "@notionhq/client";
const notion = new Client({
auth: process.env.NOTION_TOKEN,
logLevel: process.env.NODE_ENV !== 'production' ? LogLevel.DEBUG : undefined
});
export const getPage = async (pageId:string) => {
const response = await notion.pages.retrieve({ page_id: pageId });
// ↓ Error this Line !!!
const pageTitle = response.properties.Name.title[0].plain_text;
console.log(pageTitle);
return response;
};
当使用 notion-API 检索块时, 我收到与上述类似的错误,无法正确获取该属性。 该类型被视为any,这会导致编辑器出错,但可以在浏览器中正确检索。
如何消除编辑器中的错误?
这个问题也可能是编辑器或打字稿的问题。 请给我一些提示????️.
感谢您在我之前回答!
Property 'properties' does not exist on type 'GetPageResponse'.
Property 'properties' does not exist on type '{ object: "page"; id: string; }'.ts(2339)
主环境是这样的
// package.json
{
"name": "notion-api-test",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"typelint": "tsc --noEmit"
},
"dependencies": {
"@chakra-ui/icons": "^1.1.1",
"@chakra-ui/react": "^1.7.4",
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@notionhq/client": "^0.4.12",
"firebase": "^9.6.3",
"framer-motion": "^5.6.0",
"next": "12.0.8",
"react": "17.0.2",
"react-dom": "17.0.2",
"recoil": "^0.5.2",
"swr": "^1.1.2"
},
"devDependencies": {
"@types/node": "^17.0.9",
"@types/react": "^17.0.38",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"eslint": "8.7.0",
"eslint-config-next": "12.0.8",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"focus-visible": "^5.2.0",
"prettier": "^2.5.1",
"typescript": "^4.5.4"
}
}
// vscode
Version: 1.63.2
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:38:17.605Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin arm64 21.1.0
node --version
v16.8.0
【问题讨论】:
标签: reactjs typescript visual-studio-code next.js