notion-sdk-js icon indicating copy to clipboard operation
notion-sdk-js copied to clipboard

Typescript error when assigning null to select property

Open laripereira14 opened this issue 3 years ago • 1 comments
trafficstars

For assigning a value to a select property that could be empty when creating a page, I'm doing:

"Year": {
	select: !data.year ? null : { name: data.year } 
},

and it works fine, the page gets created with an empty value, but typescript says that null is not assignable: image

laripereira14 avatar Aug 02 '22 14:08 laripereira14

Hi @laripereira14 ! Thanks for filing an issue. We have tested this on our end and a request that looks like the following passes the typecheck:

const data: { year: string | null } = { year: "1882" };

const response = await notion.pages.create({
	parent: {
		database_id: "d0e59976398b4418a9fd56ed463012c4",
	},
	properties: {
		Name: {
			title: [
				{
					text: {
						content: "hi",
					},
				},
			],
		},
		Tags: {
			select: !data.year ? null : { name: data.year },
		},
	},
});

Can you paste your entire request? There may be a type issue with another part of the request.

xoxohorses avatar Sep 07 '22 21:09 xoxohorses