Open1
Notion API を TypeScript で書くと変な型エラーが出る
これは型エラーをts-ignoreして、ちゃんと動くのを確認したバージョン。
/package.json
{
//略
"engines": {
"node": "14.x"
},
"scripts": {
"test": "ts-node -r dotenv/config index.ts"
},
"dependencies": {
"@notionhq/client": "^0.1.3"
},
"devDependencies": {
"dotenv": "^9.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
}
}
/.env
NOTION_TOKEN = <Notion Internal Integration Token>
BLOCK_ID = <Notion Page ID>
/index.ts
(このコードはAPIリファレンスのNotion SDK for JavaScriptとほぼ同じ。import, env, ts-ignoreの部分を変えただけ)
import { Client } from "@notionhq/client";
const notion = new Client({ auth: process.env.NOTION_TOKEN });
(async () => {
const blockId = process.env.BLOCK_ID!;
const response = await notion.blocks.children.append({
block_id: blockId,
children: [
{
object: "block",
type: "heading_2",
// @ts-ignore
heading_2: {
text: [
{
type: "text",
text: {
content: "Lacinato kale",
},
},
],
},
},
{
object: "block",
type: "paragraph",
// @ts-ignore
paragraph: {
text: [
{
type: "text",
text: {
content:
"Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
link: {
url: "https://en.wikipedia.org/wiki/Lacinato_kale",
},
},
},
],
},
},
],
});
console.log(response);
})();
↑なら上手くいくが、
ts-ignoreを外してAPIリファレンスに載っていた本来のコードにすると型エラーが出る。
どういうことだろう・・・?