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: docs/jsx.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -281,7 +281,9 @@ function ChildComponent(vNode: Vnode<Attributes>): m.Component<Attributes> {
281
281
282
282
function ParentComponent() {
283
283
return {
284
-
view: <div><ChildComponentgreet="Hello World"/></div> //This line will compile correctly but shows the errors bellow
284
+
view: () => <div>
285
+
<ChildComponentgreet="Hello World"/>
286
+
</div>
285
287
};
286
288
}
287
289
```
@@ -293,17 +295,15 @@ TS2739: Type { greet: string; } is missing the following properties from type Vn
293
295
TS2786: ChildComponent cannot be used as a JSX component.
294
296
```
295
297
296
-
There are several options to circumvent that problem:
298
+
There are a few options to circumvent that problem:
297
299
1. Instead of `<div><ChildComponent greet="Hello World"/></div>`, use [hyperscript](hyperscript.md) instead: `<div>{m(ChildComponent, {greet: "Hello World"})}</div>`.
298
300
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`).
299
-
3. Create a "translation function" (see`TsClosureComponent()` in the example below) to trick TypeScript.
301
+
3. Create a "translation function" (like`TsClosureComponent()` in the example below) to trick TypeScript.
300
302
301
303
The following code will work without errors:
302
304
303
305
```tsx
304
-
/**
305
-
* Use TsClosureComponent to create closure components that can be inspected by TypeScript.
306
-
*/
306
+
// Use this helper to force TypeScript to treat closure components as valid JSX components
0 commit comments