You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2025-02-14-typescript-sdk-release.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Today we are excited to announce the availability of version 0.14 of our TypeScr
8
8
9
9
This release is a big step forward, significantly improving the type safety of our `@atproto/api` package. Let’s take a look at the highlights:
10
10
11
-
-**Lexicon derived interfaces now have an explicitly defined `$type` property**, allowing to properly discriminate unions.
11
+
-**Lexicon derived interfaces now have an explicitly defined `$type` property**, allowing proper discrimination of unions.
12
12
-**Lexicon derived `is*` utility methods no longer unsafely type cast their input**.
13
13
-**Lexicon derived `validate*` utility methods now return a more precise type**.
14
14
@@ -28,7 +28,7 @@ This release is a big step forward, significantly improving the type safety of o
28
28
29
29
## Context
30
30
31
-
Atproto is an "open protocol" which means a lot of things. One of these things is that the data structures handled through the protocol are extensible. Lexicons (which is the syntax used to define the schema of the data structures) can be used to describe placeholders where arbitrary data types (defined through thirdparty Lexicons) can be used.
31
+
Atproto is an "open protocol" which means a lot of things. One of these things is that the data structures handled through the protocol are extensible. Lexicons (which is the syntax used to define the schema of the data structures) can be used to describe placeholders where arbitrary data types (defined through third-party Lexicons) can be used.
32
32
33
33
An example of such a placeholder exists in the Lexicon definition of a Bluesky post
34
34
([`app.bsky.feed.post`](https://github.com/bluesky-social/atproto/blob/5ece8c6aeab9c5c3f51295d93ed6e27c3c6095c2/lexicons/app/bsky/feed/post.json#L5-L64)), which enables posts to have an `embed` property defined as follows:
@@ -46,7 +46,7 @@ An example of such a placeholder exists in the Lexicon definition of a Bluesky p
46
46
}
47
47
```
48
48
49
-
The type of the `embed` property is what is called an "open union". It means that the `embed` field can basically contain anything, although we usually expect it to be one of the known types defined in the `refs` array of the Lexicon schema (an image, a video, a link or another post).
49
+
The type of the `embed` property is what is called an "open union". It means that the `embed` field can basically contain anything, although we usually expect it to be one of the known types defined in the `refs` array of the Lexicon schema (an image, a video, a link, or another post).
50
50
51
51
Systems consuming Bluesky posts need to be able to determine what type of embed they are dealing with. This is where the `$type` property comes in. This property allows systems to uniquely determine the Lexicon schema that must be used to interpret the data, and it **must** be provided everywhere a union is expected. For example, a post with a video would look like this:
Because the `$type` property of objects is required in some contexts while optional in others, we introduced a new utility type to make it required when needed. The `$Typed` utility allows to mark an interface’s `$type` property nonoptional in contexts where it is required:
194
+
Because the `$type` property of objects is required in some contexts while optional in others, we introduced a new utility type to make it required when needed. The `$Typed` utility allows marking an interface’s `$type` property non-optional in contexts where it is required:
195
195
196
196
```typescript
197
197
exporttype$Typed<V> =V& { $type:string }
@@ -221,7 +221,7 @@ import { AppBskyFeedPost } from '@atproto/api'
221
221
typeBlueskyPost=AppBskyFeedPost.Main
222
222
223
223
// Say we got some random post somehow (typically
224
-
// via an api call)
224
+
// via an API call)
225
225
declareconst post:BlueskyPost
226
226
227
227
// And we want to know what kind of embed it contains
@@ -230,7 +230,7 @@ const { embed } = post
230
230
// We can now use the `$type` property to disambiguate
// discriminate **valid** data based on their `$type`
312
312
if (isImages(post.embed)) {
313
313
// `post.embed` is fully typed as
314
-
// `$Typed<AppBskyEmbedImages.Main>` here!
314
+
// `$Typed<AppBskyEmbedImages.Main>` here!
315
315
}
316
316
```
317
317
@@ -362,7 +362,7 @@ if (result.success) {
362
362
363
363
### New `asPredicate` function
364
364
365
-
The SDK exposes a new `asPredicate` function. This function allows to convert a `validate*` function into a predicate function. This can be useful when working with libraries that expect a predicate function to be passed as an argument.
365
+
The SDK exposes a new `asPredicate` function. This function allows converting a `validate*` function into a predicate function. This can be useful when working with libraries that expect a predicate function to be passed as an argument.
0 commit comments