Skip to content

Conversation

@Zamiell
Copy link
Contributor

@Zamiell Zamiell commented Aug 3, 2021

also made the previous section better


```ts title=main.ts
import { myFunction } from "./somelua";
import { myFunction } from "./someLua";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

myFunction is not in someLua.lua, please change main.ts to reflect the contents you gave to someLua

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, fixed now

}
```

In normal TypeScript code that imports an array, you would typically use the `export default` functionality of ES6 imports. But you can't do that here, because Lua code has no import named `default`. Instead, you have to use `export =` syntax, like so:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, we support export/import default functionality just fine, it's just that your lua file does not return a module (table) with a member named default

Then, in your TypeScript code, you can import it exactly like you would expect:

```ts title=main.ts
import contents from "./module";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually correct? I thought this should be import * as contents from "./module";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further investigation, you're right, but it depends on whether or not you have --esModuleInterop flag turned on. I'll change it to be import *.

import contents from "./module";
```

Finally, note that for this to work, `esModuleInterop` must be specified as true in your `tsconfig.json` file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have my doubts if this line should be in here, tstl actually does not look at this option at all, if this needs to have a certain value it would be purely to keep TS happy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i removed it

@Zamiell
Copy link
Contributor Author

Zamiell commented Aug 4, 2021

This is incorrect, we support export/import default functionality just fine, it's just that your lua file does not return a module (table) with a member named default

I rewrote the section now to be worded differently, maybe that will address this issue

@Perryvw Perryvw merged commit fb23b40 into TypeScriptToLua:source Aug 5, 2021
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

Successfully merging this pull request may close these issues.

2 participants