Reputation: 21
I recently created a TypeScript project for a relatively complex simulation engine using Visual Studio which, by default, targeted ECMAScript 3 (ES3). I wanted to start using real properties in my TypeScript classes, so I updated my project file to target ES5, like so:
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptRemoveComments>true</TypeScriptRemoveComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
Now when I run my application in IE (v10), I get a run-time exception: "0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'defineProperty'". If I switch to launching my application with any other browser (e.g., Firefox, Chrome), it works as expected - no errors. I can't seem to find any reason why IE isn't working as expected. I found a website that confirmed that, in general, my IE browser supports 'defineProperty', so now I'm really baffled as to why it won't work during development. This is getting particularly critical since I can't debug my TypeScript code in VS. Any thoughts?
Upvotes: 2
Views: 13746
Reputation: 275917
Make sure that the first line of your HTML file is
<!doctype html>
This will prevent IE from going in compatibility mode and disable ES5 features.
Upvotes: 1
Reputation: 250932
According to the ES5 Compatibility table Object.defineProperty is supported in IE9 and above.
Support in IE8 is limited.
However, IE10 has a habit of running local and intranet pages in compatibility mode, even though the same pages run in normal mode over the Internet.
You can change this in the dialog in Tools > Compatibility View Settings (remove the "Display intranet sites in compatibility mode" option. You can also prevent this using a combination of the correct doctype:
<!DOCTYPE html>
Or a user-agent compatibility tag, which will no longer be required (or supported) in IE11 and above.
<meta http-equiv="x-ua-compatible" content="IE=edge">
This must be the first tag within the <head>
element.
Upvotes: 11