0.2.13 • Published 2 months ago

live-typescript v0.2.13

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

A simple React component to show live Typescript code samples.

  • TypesScript hinting and error checking using the Monaco editor from VS Code.
  • Your example code is vanilla Typescript.
  • Example code can import local packages (not just public packages on npm).
  • Live preview, isolated in an iframe.
  • Instant refresh, transpiles with sucrase.
  • Docusaurus compatible.

Examples

Here's a simple example:

  <LiveTypescript code="console.log('hello world');"/>

To import modules in your example code, use the provided plugin in a vite or rollup build: rollup-plugin-sourcefiles.

  import pkgSource from "thimbleberry?sourceFiles";

  <LiveTypescript embeddedPackages={[pkgSource]}
      code="
        import { mapN } from 'thimbleberry';

        const seq = mapN(10).join(' ');
        document.body.innerHTML = `<div> ${seq} </div>`;
      "
    > </LiveTypescript>

Here's a complete example using vite.

Docusaurus

LiveTypescript works well in Docusaurus.

The recommended approach is to build (and test) your code examples in a separate vite/rollup package build, and then import the examples package into your documentation build.

Consider wrapping your LiveTypescript component in <BrowserOnly>. The current sandboxed execution doesn't run on the server anyway, and server side rendering can lead to developer console warnings at runtime.

0.2.13

2 months ago

0.2.11

7 months ago

0.2.10

7 months ago

0.2.7

7 months ago

0.2.6

7 months ago

0.2.9

7 months ago

0.2.5

7 months ago

0.2.4

8 months ago

0.2.3

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.4

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago