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

Simple code in TS not working #90

Closed
anant-k-singh opened this issue Apr 27, 2020 · 3 comments
Closed

Simple code in TS not working #90

anant-k-singh opened this issue Apr 27, 2020 · 3 comments

Comments

@anant-k-singh
Copy link

anant-k-singh commented Apr 27, 2020

I guess I am not using it correctly,

import memoizeOne from 'memoize-one';

const print = (list: Array<number>): void => list.forEach(num => {
    console.log(num);
});

const mem_print = memoizeOne(print);

let list = [1,2,3];

mem_print(list);
mem_print(list);

list = [...list, 4];

mem_print(list);

Compiled from TS 3.8 to JS with tsc index.js

"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
exports.__esModule = true;
var memoize_one_1 = require("memoize-one");
var print = function (list) { return list.forEach(function (num) {
    console.log(num);
}); };
var mem_print = memoize_one_1["default"](print);
var list = [1, 2, 3];
mem_print(list);
mem_print(list);
list = __spreadArrays(list, [4]);
mem_print(list);

Output:

var mem_print = memoize_one_1["default"](print);
                                        ^

TypeError: memoize_one_1.default is not a function
    at Object.<anonymous> (D:\MyGit\plaints\index.js:14:41)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

tsconfig

{
	"compilerOptions": {
		"target": "ES2018",
		"esModuleInterop": true,
		"allowSyntheticDefaultImports": true,
		"strict": true,
		"module": "esnext",
		"moduleResolution": "node",
	}
}
@TrySound
Copy link
Contributor

See big thread
#37

Shortly, enable esModuleInterop in your ts config.

@anant-k-singh
Copy link
Author

anant-k-singh commented Apr 27, 2020

Same issue with esModuleInterop: true.
My tsconfig

{
	"compilerOptions": {
		"target": "ES2018",
		"esModuleInterop": true,
		"allowSyntheticDefaultImports": true,
		"strict": true,
		"module": "esnext",
		"moduleResolution": "node",
	}
}

@alexreardon
Copy link
Owner

Please reopen if this is still a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants