Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions website/docs/how-to-guides/intermediate-semantic-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ Query parameters are represented as the type
`Record<string, string | string[] | undefined>`, so using a codec that doesn't decode
from a `string | string[] | undefined` will produce a type error.

<CH.Spotlight>

Consider this `httpRoute` that compiles successfully.

```typescript spec.ts
```typescript
import * as t from 'io-ts';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';

Expand All @@ -30,9 +28,10 @@ const GetHello = httpRoute({
});
```

---
If you add an expected `number` value to the `httpRoute`'s query parameters, you'll see
the following compilation error:

```typescript spec.ts focus=14:16
```typescript
import * as t from 'io-ts';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';

Expand Down Expand Up @@ -72,8 +71,6 @@ number.
We need a codec that decodes a `string` into a `number` and converts the
string-representation of a number into the `number` type.

---

This is a fairly common requirement, so this codec already exists: [io-ts-types] offers
the [NumberFromString] codec that decodes a `string` value into a `number`. Use
`NumberFromString` to fix your compilation error.
Expand All @@ -82,7 +79,7 @@ the [NumberFromString] codec that decodes a `string` value into a `number`. Use
[numberfromstring]:
https://gcanti.github.io/io-ts-types/modules/NumberFromString.ts.html

```typescript spec.ts focus=2,15:17
```typescript
import * as t from 'io-ts';
import { NumberFromString } from 'io-ts-types';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
Expand All @@ -104,7 +101,5 @@ const GetHello = httpRoute({
});
```

</CH.Spotlight>

In general, the solution to decoding a query parameter into a non-string type is to use
a codec that decodes and encodes from a `string` into your desired type.
8 changes: 3 additions & 5 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const darkCodeTheme = require('prism-react-renderer/themes/dracula');

// Remove the shiki theme import that's causing the error
// const theme = require('shiki/themes/nord.json');
const { remarkCodeHike } = require('@code-hike/mdx');
const { remarkCodeHike, recmaCodeHike } = require('codehike/mdx');

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand Down Expand Up @@ -39,6 +39,7 @@ const config = {
docs: {
// Update to use a default theme instead of the missing nord theme
beforeDefaultRemarkPlugins: [[remarkCodeHike, { theme: 'github-dark' }]],
recmaPlugins: [[recmaCodeHike, { theme: 'github-dark' }]],
sidebarPath: require.resolve('./sidebars.js'),
// Remove this to remove the "edit this page" links.
editUrl: 'https://github.com/BitGo/api-ts/tree/master/website/',
Expand All @@ -49,10 +50,7 @@ const config = {
editUrl: 'https://github.com/BitGo/api-ts/tree/master/website',
},
theme: {
customCss: [
require.resolve('@code-hike/mdx/styles.css'),
require.resolve('./src/css/custom.css'),
],
customCss: [require.resolve('./src/css/custom.css')],
},
}),
],
Expand Down
105 changes: 36 additions & 69 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@code-hike/mdx": "^0.9.0",
"@docusaurus/core": "3.7.0",
"@docusaurus/preset-classic": "3.7.0",
"@mdx-js/react": "^3.0.0",
"clsx": "^1.2.1",
"codehike": "^1.0.5",
"docusaurus-theme-mdx-v2": "^0.1.2",
"prism-react-renderer": "^1.3.5",
"react": "^18.0.0",
Expand Down