0

I am trying out Typescript, using visual studio 2017.

I opened a blank directory in Visual studio 2017 ("Add Existing Website"), and added index.html and main.ts.

This is my tsconfig.json file, based on general recommendations:

    {
    "compilerOptions":
    {
        "sourceMap": false,
        "noImplicitAny": false,
        "module": "es2015",
        "target": "es3"
    },
    "compileOnSave": true,
    "include":
    [
        "scripts/**/*"
    ]
}

And in index.html i add my file as follows:

 <script src="scripts/main.js" ></script>

But when i open the page in IE11, i just shows "Syntax error" and the line number. Going to the line number shows import and export statements

I've tried using requirejs but i get other kinds of errors, and i've tried changing the module and target in tsconfig.json but nothing seems to have worked.

I don't want dependencies in my code if at all possible, but what do i have to do to get Typescript generated javascript code to execute in IE11?

I have not even attempted to get it to work as far back as IE8.

Or is IE11 no longer considered a browser to be supported ?

1 Answer 1

1

I found a solution...

I had code like this:

export module ABC {
    ....
}

And in IE11 this created an error "unknown error exports" as a result of the way JS was generated using the tsconfig settings.

So the solution was to replace export module ABC with namespace ABC and update my tsconfig.js as follows:

{
"compilerOptions":
{
    "target": "es3", //defines what sort of code ts generates, es5 because it's what most browsers currently UNDERSTANDS.
    "module": "none",
    "lib":
    [
        "es2015.promise",
        "es5",
        "dom",
    ]
},
"compileOnSave": true,
"include":
[
    "scripts/*"
]

}

Most important was the "module" : "none"

Took me ages to figure out, hope it helps someone else.

UPDATE 1:

I had to add the "lib" section in compiler options to get the transpiler to not complain about Promise, console and other known keywords.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.