Skip to content

Commit

Permalink
docs: fix overlapping optionality warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalbdivad committed Nov 20, 2024
1 parent 2add9d2 commit 72c5604
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions ark/docs/src/content/docs/objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const myObject = type({

</Tabs>

:::caution[Optional properties cannot be present with the value `undefined` unless specified]
:::caution[Optional properties cannot be present with the value undefined]

In TypeScript, there is a setting called `exactOptionalPropertyTypes` that can be set to `true` to enforce the distinction between properties that are missing and properties that are present with the value `undefined`.

Expand All @@ -127,30 +127,6 @@ const errorResult = myObj({ key: undefined })
```

</details>

:::caution[Optional and default only work within objects!]
Adding a `optional` or `default` to a `Type` doesn't alter its standalone behavior.

Rather, it adds metadata that changes how it works when referenced from an object or tuple.

<details>
<summary>See an example</summary>

```ts
const optionalString = type.string.optional()

optionalString.allows(undefined) // false

const objectWithOptionalKey = type({
foo: optionalString
})

objectWithOptionalKey.allows({}) // true
```

</details>

Prefer the key-embedded syntax (`"optionalKey?":`) where possible.
:::

<a name="properties/defaultable" />
Expand Down Expand Up @@ -199,6 +175,31 @@ const myObject = type({

</Tabs>

:::caution[Optional and default only work within objects!]
Adding a `optional` or `default` to a `Type` doesn't alter its standalone behavior.

Rather, it adds metadata that changes how it works when referenced from an object or tuple.

<details>
<summary>See an example</summary>

```ts
const optionalString = type.string.optional()

optionalString.allows(undefined) // false

const objectWithOptionalKey = type({
foo: optionalString
})

objectWithOptionalKey.allows({}) // true
```

</details>

Prefer the key-embedded syntax (`"optionalKey?":`) where possible.
:::

<a name="properties/index" />
##### index

Expand Down

0 comments on commit 72c5604

Please sign in to comment.