Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating over Python iterables from TypeScript always returns undefined for the iterator value #47

Open
mmomtchev opened this issue Dec 26, 2022 · 1 comment
Labels
wontfix This will not be worked on

Comments

@mmomtchev
Copy link
Owner

Consider the following TypeScript code:

import { PyObject } from 'pymport/proxified';

const d = PyObject.dict({a: 1, b: 2});
for (const i of d) console.log(i);

Instead of outputting

a
b

it outputs

undefined
undefined
@mmomtchev mmomtchev added the wontfix This will not be worked on label Dec 26, 2022
@mmomtchev
Copy link
Owner Author

This is in fact a TypeScript issue, by default tsc transpiles this to the following JS code:

"use strict";
exports.__esModule = true;
var proxified_1 = require("pymport/proxified");
var d = proxified_1.PyObject.dict({ a: 1, b: 2 });
for (var _i = 0, d_1 = d; _i < d_1.length; _i++) {
    var i = d_1[_i];
    console.log(i);
}

which explains the output - a d is an iterable but not a subscriptable.

Use the TypeScript transpiler option "downlevelIteration": true to achieve correct behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant