-3

This test.html page fails on Google Chrome (April 2019, Version 73.0.3683.86)

<html>
<body>
<script>
const str: string = "hello";
alert(a);
</script>
</body>

It complains with Uncaught SyntaxError: Missing initializer in const declaration This shows that Google Chrome does not understand typescript.

I tried also with <script type="application/ecmascript">, but I get the same error. Can I use typescript directly on Google Chrome (without trans-compiling to javascript)?

David Portabella
  • 12,390
  • 27
  • 101
  • 182
  • 4
    "Can I use typescript directly on Google Chrome" No. Google Chrome (like all major browsers) has a JS engine, not TS. – Seblor Apr 04 '19 at 12:57
  • Possible duplicate of [How to use typescript in browser?](https://stackoverflow.com/questions/41620921/how-to-use-typescript-in-browser) – CoderPi Apr 04 '19 at 12:58
  • @CoderPi The question you linked is not the same. In yours, the person asking seems to have trouble transpiling, because they transpile into a module. – Seblor Apr 04 '19 at 13:00

1 Answers1

1

No you can not. The browser has a JavaScript engine and not a TypeScript engine. TypeScript has to be compiled to JavaScript, you can use Source Mappings to show the TypeScript when you inspect it.

Murf
  • 1,661
  • 11
  • 18