Skip to content

Commit 9ceeed5

Browse files
authored
Generic constructors. Refs #281 (comment) 🌹
1 parent 7628263 commit 9ceeed5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/jsx/tsx.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ const StringSelect = Select as { new (): Select<string> };
100100
/** Usage */
101101
const Form = () => <StringSelect items={['a','b']} />;
102102
```
103+
If your constructor takes props you can accomodate that too:
104+
105+
```ts
106+
/** Generic component */
107+
interface SelectProps<T> { items: T[] }
108+
class Select<T> extends Component<SelectProps<T>, any> {
109+
constructor(props: SelectProps<T>) { super(props) }
110+
}
111+
/** Specialization */
112+
const StringSelect = Select as { new (props: SelectProps<string>): GenericList<string> };
113+
```
114+
103115
## Non React JSX
104116
TypeScript provides you with the ability to use something other than React with JSX in a type safe manner. The following lists the customizability points, but note that this is for advanced UI framework authors:
105117

0 commit comments

Comments
 (0)