0

I'm doing again an online angular course because I'm a little bit rusty and following one of the first classes I got an error declaring an interface.

interface face{
    name: string;
    address: string;
}

I get this error Uncaught SyntaxError: unexpected token: identifier in firefox and chrome, but in a online editor my code works. I don't know which identifier is wrong, it could be a error because of a non updated version of something?

Edited: This is the html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Intro ducción</title>
    </head>
    <body>
        <script src="app.ts"></script>
    </body>
</html>

And this is the tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */
  }
}
ivanimg
  • 7
  • 4
  • Share us the screen shot of browser console. otherwise its impossible to debug and provide answer. Such questions will be closed shortly. so please provide more details – Shashank Vivek Oct 10 '20 at 18:40

2 Answers2

0

Browsers understand only Javascript, but javascript do not have interface type in it. That's why it is giving error.

Check Does JavaScript have the interface type (such as Java's 'interface')?.

Allah-The-Dev
  • 57
  • 2
  • 8
0

You need to run your typescript code through the typescript compiler first. You can't declare typescript like this directly in the browser.

Most likely the online editor you are using is doing this compilation step for you.

This should help you get started: https://basarat.gitbook.io/typescript/browser

dwosk
  • 1,202
  • 8
  • 11
  • I'm using **tsc** after every change, could it be something of configuration in **tsconfig.json**? – ivanimg Oct 11 '20 at 16:43
  • Does the file with this interface have a .ts extension? it'll be hard to figure out the issue without some more information. maybe a screenshot would help. – dwosk Oct 11 '20 at 16:46
  • Yes, it's directory with an index.html. an app.ts, an app.js and a tsconfig.json, like I said it's a simple exercise – ivanimg Oct 11 '20 at 16:52