Skip to content

Commit dbb8f98

Browse files
committed
feat: export react typings #35
Currently, using wokwi elements within a React TypeScript projects results in errors such as: Property 'wokwi-led' does not exist on type 'JSX.IntrinsicElements'. This adds the required typings so that TypeScript recognizes all the Wokwi elements within the JSX context.
1 parent a83e892 commit dbb8f98

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
to: src/react-types.ts
3+
inject: true
4+
before: \ndeclare global
5+
skip_if: \{ <%= h.className(name) %>Element \}
6+
---
7+
import { <%= h.className(name) %>Element } from './<%= name %>-element';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
to: src/react-types.ts
3+
inject: true
4+
before: \}\s+\}\s+\}
5+
skip_if: 'wokwi-<%= name %>'
6+
---
7+
'wokwi-<%= name %>': Partial<<%= h.className(name) %>Element>;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './react-types';
12
export { SevenSegmentElement } from './7segment-element';
23
export { ArduinoUnoElement } from './arduino-uno-element';
34
export { LCD1602Element } from './lcd1602-element';

src/react-types.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable @typescript-eslint/no-namespace */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
4+
import { SevenSegmentElement } from './7segment-element';
5+
import { ArduinoUnoElement } from './arduino-uno-element';
6+
import { BuzzerElement } from './buzzer-element';
7+
import { LCD1602Element } from './lcd1602-element';
8+
import { LEDElement } from './led-element';
9+
import { MembraneKeypadElement } from './membrane-keypad-element';
10+
import { NeoPixelElement } from './neopixel-element';
11+
import { NeopixelMatrixElement } from './neopixel-matrix-element';
12+
import { PotentiometerElement } from './potentiometer-element';
13+
import { PushbuttonElement } from './pushbutton-element';
14+
import { ResistorElement } from './resistor-element';
15+
import { RotaryDialerElement } from './rotary-dialer-element';
16+
import { SSD1306Element } from './ssd1306-element';
17+
18+
declare global {
19+
namespace JSX {
20+
interface IntrinsicElements {
21+
'wokwi-7segment': Partial<SevenSegmentElement>;
22+
'wokwi-arduino-uno': Partial<ArduinoUnoElement>;
23+
'wokwi-lcd1602': Partial<LCD1602Element>;
24+
'wokwi-led': Partial<LEDElement>;
25+
'wokwi-neopixel': Partial<NeoPixelElement>;
26+
'wokwi-pushbutton': Partial<PushbuttonElement>;
27+
'wokwi-resistor': Partial<ResistorElement>;
28+
'wokwi-membrane-keypad': Partial<MembraneKeypadElement>;
29+
'wokwi-potentiometer': Partial<PotentiometerElement>;
30+
'wokwi-neopixel-matrix': Partial<NeopixelMatrixElement>;
31+
'wokwi-ssd1306': Partial<SSD1306Element>;
32+
'wokwi-buzzer': Partial<BuzzerElement>;
33+
'wokwi-rotary-dialer': Partial<RotaryDialerElement>;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)