Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - Object doesn't support property or method 'defineProperty'

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?

like image 854
7dino7 Avatar asked Aug 03 '26 23:08

7dino7


1 Answers

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.

like image 68
Fenton Avatar answered Aug 06 '26 12:08

Fenton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!