Skip to content

Commit 5f041de

Browse files
Improve closure compiler example
Co-authored-by: Claudia Meadows <[email protected]>
1 parent 9f77526 commit 5f041de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/jsx.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,7 @@ m.fragment = { view: (vNode: Vnode) => vNode.children } as any;
282282
#### Using Closure Components in TSX
283283
When using [Closure Components](components.md#closure-component-state) in JSX, TypeScript only expects an attribute object as a parameter for a Function Component. But Mithril provides a `Vnode` object instead. This leads to the IDE showing faulty parameters even though the JSX would compile correctly.
284284

285-
Example:
286-
The following code will compile correctly but show this error:
287-
```
288-
TS2739: Type { greet: string; } is missing the following properties from type Vnode<{}, {}>: tag, attrs, state
289-
TS2786: LoadingSpinner cannot be used as a JSX component.
290-
```
285+
For example, if you try to compile this code:
291286

292287
```typescript jsx
293288
interface Attributes {
@@ -306,6 +301,13 @@ function ParentComponent() {
306301
}
307302
```
308303

304+
TypeScript will report this error:
305+
306+
```
307+
TS2739: Type { greet: string; } is missing the following properties from type Vnode<{}, {}>: tag, attrs, state
308+
TS2786: LoadingSpinner cannot be used as a JSX component.
309+
```
310+
309311
There are several options to circumvent that problem:
310312
1) Instead of `<div><ChildComponent greet="Hello World"/></div>`, use `<div>{m(ChildComponent, {greet: "Hello World"})}</div>` instead.
311313
2) Use [Class Components](components.md#class-component-state) instead. Class Components will not show any errors. But TypeScript will not be able to autocomplete or inspect attributes (in this example `greet` would be unknown when used in `ParentComponent`).

0 commit comments

Comments
 (0)