This issue is a suggestion.
Describe the bug
When dealing with formula property, I noticed :
type FormulaPropertyResponse = StringFormulaPropertyResponse | DateFormulaPropertyResponse | NumberFormulaPropertyResponse | BooleanFormulaPropertyResponse;
This way, if I have 2 properties in my datasource (one string, other a date), typescript cannot give me the corresponding type.
To Reproduce
Node version: 24.11.1
Notion JS library version: 5.6.0
Steps to reproduce the behavior:
- Have at least one formula property in database ;
- Make a datasource query with notion sdk ;
- Retrieve formula value
Expected behavior
Currently I use this workaround :
{
id: result.id,
slug:
"string" in properties.slug.formula &&
properties.slug.formula.string
? properties.slug.formula.string
: ""
}
I have to manually check if formula contains the wanted value.
We can solve this by doing this way :
export type FormulaPropertyItemObjectResponse<T extends string | Date | number | boolean> = {
type: "formula";
formula: FormulaPropertyResponse<T>;
object: "property_item";
id: string;
};
type FormulaPropertyResponse<T extends string | Date | number | boolean> = T extends string ? StringFormulaPropertyResponse : T extends Date ? DateFormulaPropertyResponse : T extends number ? NumberFormulaPropertyResponse : T extends boolean ? BooleanFormulaPropertyResponse : never;
Usage :
export type NotionArticleDTO = {
slug: FormulaPropertyItemObjectResponse<string>;
title: TitlePropertyItemObjectResponse;
publishedAt: FormulaPropertyItemObjectResponse<Date>;
status: StatusPropertyItemObjectResponse;
category: SelectPropertyItemObjectResponse;
};
What do you think about that ?
This issue is a suggestion.
Describe the bug
When dealing with formula property, I noticed :
This way, if I have 2 properties in my datasource (one string, other a date), typescript cannot give me the corresponding type.
To Reproduce
Node version: 24.11.1
Notion JS library version: 5.6.0
Steps to reproduce the behavior:
Expected behavior
Currently I use this workaround :
I have to manually check if formula contains the wanted value.
We can solve this by doing this way :
Usage :
What do you think about that ?