Skip to content

Instantly share code, notes, and snippets.

@oze4
Created August 29, 2021 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oze4/657e1f5b60631394901678bff5462137 to your computer and use it in GitHub Desktop.
Save oze4/657e1f5b60631394901678bff5462137 to your computer and use it in GitHub Desktop.
Babel+TS in browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="root"></div>
<!-- Load Babel Standalone, this is what "dumbs down" TS code so your browser can read it -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Notice the 'type="text/babel"' attribute -->
<script type="text/babel">
interface User {
Name: string;
Age: number;
}
const bob: User = {
Name: "Bob",
Age: 60
}
const el: Element = document.querySelector("#root");
el.innerHTML = JSON.stringify(bob, null, 2);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment