Comments (3)
I also tried using a type guard here in the filter but using the following code
const posts : Post[] = database.results
.filter((response) => isFullPage(response))
.map((response ) => ({
id: response.id,
title: response.properties.Name["title"][0].plain_text,
slug: response.properties.Slug["rich_text"][0].plain_text,
cover: response.properties.Image["files"][0]?.file.url
}));
I got the following error:
Argument of type
PageObjectResponse | PartialPageObjectResponse | PartialDatabaseObjectResponse | DatabaseObjectResponse
is not assignable to parameter of type
PageObjectResponse | PartialPageObjectResponse
Type PartialDatabaseObjectResponse is not assignable to type
PageObjectResponse | PartialPageObjectResponse
Type PartialDatabaseObjectResponse is missing the following properties from type PageObjectResponse : parent, icon, cover, created_by , and 6 more.
from notion-sdk-js.
I tried to write my own type guard which seems to work a little bit better
const posts : Post[] = database.results
.filter(isPageObjectResponse)
.map( (response) => ({
id: response.id,
title: response.properties.Name["title"][0].plain_text,
slug: response.properties.Slug["rich_text"][0].plain_text,
cover: response.properties.Image["files"][0]?.file.url
}));
function isPageObjectResponse(response: any): response is PageObjectResponse {
return !!response.properties;
}
Now it know that there is a property called properties but doesn't know about the specific properties I have like name,slug and Image.
Element implicitly has an any type because expression of type "title" can't be used to index type
{ type: "number"; number: number | null; id: string; } | { type: "url"; url: string | null; id: string; } | { type: "select"; select: SelectPropertyResponse | null; id: string; } | ... 18 more ... | { ...; }
Property title does not exist on type
{ type: "number"; number: number | null; id: string; } | { type: "url"; url: string | null; id: string; } | { type: "select"; select: SelectPropertyResponse | null; id: string; } | ... 18 more ... | { ...; }
from notion-sdk-js.
Finally this works but just seems hacky to me. Sorry for the rambling, just taking you through my thought process
const posts : Post[] = database.results
.filter(isPageObjectResponse)
.map( (response) => ({
id: response.id,
title: (response.properties.Name as any)["title"][0].plain_text,
slug: (response.properties.Slug as any)["rich_text"][0].plain_text,
cover: (response.properties.Image as any)["files"][0]?.file.url
}));
from notion-sdk-js.
Related Issues (20)
- The attribute `name` in database properties is not respected
- I am experiencing difficulties logging into Notion on the Windows platform. This issue seems to be affecting the login process, preventing me from accessing my Notion workspace HOT 1
- DatabasePropertyConfigResponse is a local type HOT 2
- Reading a "Person" property from a database entry returns only the first result
- Notion Formula Has a Bug Regarding Time Formatting HOT 3
- npm install ERR! for 'parse-text-from-any-block-type' examples
- How do I get value from blocks.retrieve
- The `punycode` module is deprecated HOT 3
- Missing `request_id` type in `OauthTokenResponse`
- unable to add external to files HOT 1
- multi_select type bug HOT 1
- Error: Insufficient permissions for this endpoint.
- I found the Mar 22, 2024 bug. I caused the problem HOT 5
- NotionS
- Inconsistent type: Cursor for parameters is string|undefined but for responses is string|null HOT 1
- Types from `DatabasePropertyConfigResponse` union require a `description`
- `request_id` missing on types `GetPageResponse`, `QueryDatabaseResponse` and `GetDatabaseResponse`
- AnnotationResponse type not exported
- `UpdatePageReponse` should also contains `url` prop HOT 1
- Title is converting to timestamp format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notion-sdk-js.