Created
August 29, 2021 17:19
-
-
Save oze4/657e1f5b60631394901678bff5462137 to your computer and use it in GitHub Desktop.
Babel+TS in browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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