Commit 3aa7b89
fix(@tinacms/astro): astro check rejects generated rich-text fields passed to TinaMarkdown (tinacms#7605)
## Problem
`@tinacms/cli` 3.0.0 (tinacms#7229) types rich-text fields as
`TinaMarkdownContent` from `tinacms`:
```ts
body?: Maybe<Scalars['RichText']['output']>; // TinaMarkdownContent
```
`<TinaMarkdown>` in `@tinacms/astro` types `content` as
`TinaRichTextContent`, whose root has the literal `type: 'root'`.
`TinaMarkdownContent` has `type: string`, so TypeScript rejects the
generated field:
```
Type 'TinaMarkdownContent | null' is not assignable to type 'TinaRichTextContent'.
Type 'TinaMarkdownContent' is not assignable to type 'TinaRichTextRoot'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"root"'.
```
An Astro project that passes a queried body straight to the renderer
gets this error from `astro check`. `examples/astro/visual-editing`
passes `data._body` in `PostBody.astro` and `BlogBody.astro`. That
example does not run `astro check`, so CI did not catch it.
Before tinacms#7229 the field was `any`, and the same call compiled.
## Change
`content` accepts both types, as a root or as an array of nodes. The
React `<TinaMarkdown>` accepts the same two forms.
```ts
type GeneratedRichTextContent = {
type: string;
children: GeneratedRichTextContent[];
};
export interface TinaMarkdownProps {
content:
| TinaRichTextContent
| GeneratedRichTextContent
| GeneratedRichTextContent[];
components?: CustomComponentsMap;
}
```
- `TinaMarkdown.astro` and the placeholder in `index.ts` both use
`TinaMarkdownProps`. The two prop declarations can no longer drift
apart.
- `@tinacms/astro` does not depend on `tinacms`, so
`GeneratedRichTextContent` copies the shape instead of importing it. It
stays private to `types.ts`.
- `TinaRichTextContent` does not change. Code that narrows on it keeps
its literal types.
- Rendering does not change. Both types describe the same Plate AST.
A component that wraps `<TinaMarkdown>` can type its own prop as
`TinaMarkdownProps['content']`.
## Why not change the CLI
The CLI could detect `@tinacms/astro` and emit `TinaRichTextContent`
instead. That adds framework detection to codegen, and Astro users who
already moved to CLI 3 would see their generated types change a second
time. The mismatch sits in the renderer's prop, so the fix goes there.
## Testing
- `src/TinaMarkdown.test-d.ts` checks that `content` accepts the CLI
shape with `null` and `undefined`, an array of CLI nodes, and every
`TinaRichTextContent` value. It also checks that `content` rejects a
`string`, so a regression to `any` fails. If you remove either generated
member from the union, its case fails.
- `pnpm exec vitest run` in `packages/@tinacms/astro`: 84 tests pass, no
type errors.
- `pnpm exec tsc --noEmit`: passes.
- On an Astro 7 site with CLI 3.0.0, released `@tinacms/astro` 0.7.0
fails `astro check` with the error above. With this build, `astro check`
passes with the generated body passed through and no cast.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 6cd24ce commit 3aa7b89
6 files changed
Lines changed: 62 additions & 16 deletions
File tree
- .changeset
- packages/@tinacms/astro
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
35 | 30 | | |
36 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
146 | 164 | | |
147 | 165 | | |
148 | 166 | | |
| |||
0 commit comments