Jim Jim - 1 year ago 111
TypeScript Question

typescript for / of generating invalid javascript

I am using typescript in visual studio 2015 in an ASP.NET web application.

(default typescript settings, version - I always use

"use strict"
in my

Given the following code:

for (let file of element.files) {
file.sourceDocumentId = id;

file generated by typescript is as follows.

for (var _i = 0, _a = element.files; _i < _a.length; _i++) {
var file = _a[_i];
file.sourceDocumentId = id;

Firefox throws an exception indicating that
is undefined.

this error seems reasonable - is this a bug in typescript?

Answer Source

Comment as answer:

The code is valid, but element has no files property at runtime...

_a is undefined because element.files really is undefined. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download