GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

Cannot use table.deepcopy imported from util #15

Closed JamDon2 closed 2 years ago

JamDon2 commented 2 years ago

I'm trying to use table.deepcopy, this is what I tried so far:

import { table } from "util"
table.deepcopy(someTable)

The above code gets transpiled into this:

local ____util = require("util")
local ____table = ____util.table

____table.deepcopy(someTable)

The variable ____table is nil in the Lua code. How can I extend the table type with the table namespace from util?

GlassBricks commented 2 years ago

The type definitions still work as expected in my tests. Check that you don't have a file also named exactly util (.ts or .lua) in the root folder of your mod. If so, lua will import that file instead of the factorio lualib file. You can get around this by renaming the util file (e.g. to _util.ts) or moving it into a folder.

If there's still an issue, more information or a sample project would be useful to reproduce this.

JamDon2 commented 2 years ago

That was the case, the build folder wasn't being deleted before a new build, and a util.lua file remained.