You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[question] Is it possible to create a index.ts for both lua and js? #1681
exportasyncfunctionf(this: void,filename: string){lettext;if(io!==undefined){constf=io.open(filename)[0];if(f){text=f.read("*a");f.close();}}else{constfs=require('fs');text=String(fs.readSync())}return`file is ${text}!`}
Can you try using 2 different "tsconfig.json" files? Name them "tsconfig.js.json" and "tsconfig.lua.json", and then point tsc at the former and point tstl at the latter.
I've run into similar issue recently, in my case I wanted to have 3 separate tsconfig in the same directory, with one being the "common base" and the other two being server/client separation. I tried running tstl with -p, but it seems tstl doesn't respect "extends" property in tsconfig for some reason. Is this just me, or is this supposed to work? Nevermind, it seems to be working now (lol)
AI says:
Example TypeScriptToLua project with three tsconfig files in the same directory:
tsconfig.base.json: shared config
tsconfig.client.json: client‑side config
tsconfig.server.json: server‑side config
Each of the client/server configs extends the base config.
This is a very common setup for full-stack TypeScriptToLua monorepos or unified projects.
@types/node and lua-types conflict, due to repeated definition like require.
if we use two tsconfig.json for tsc and tstl, @types/node is OK for tsc, However, we need *.d.ts for fs. Even if we add @types/node, it doesn't have any lua source, which will result in error TSTL: Could not resolve lua source files for require path 'fs' in file index.ts.
@types/node and lua-types conflict, due to repeated definition like require.
Yeah, that's a big problem. Sounds like you are running up against some fundamental technical limitations, as TypeScript isn't meant to be used this way. I think you would have to make your own types library called "lua-and-node-types" that combined exactly what you needed from both types libraries.
Activity
Zamiell commentedon Jan 30, 2026
Can you try using 2 different "tsconfig.json" files? Name them "tsconfig.js.json" and "tsconfig.lua.json", and then point
tscat the former and pointtstlat the latter.Cheatoid commentedon Jan 31, 2026
I've run into similar issue recently, in my case I wanted to have 3 separate tsconfig in the same directory, with one being the "common base" and the other two being server/client separation.
I tried runningtstlwith-p, but it seems tstl doesn't respect"extends"property in tsconfig for some reason.Is this just me, or is this supposed to work?Nevermind, it seems to be working now (lol)AI says:
Example TypeScriptToLua project with three tsconfig files in the same directory:
tsconfig.base.json: shared configtsconfig.client.json: client‑side configtsconfig.server.json: server‑side configEach of the client/server configs extends the base config.
This is a very common setup for full-stack TypeScriptToLua monorepos or unified projects.
📁 Project Structure
🧩 1. Base Config -
tsconfig.base.jsonThis contains all shared TSTL settings.
{ "compilerOptions": { "strict": true, "types": [] }, "tstl": { "luaTarget": "5.4" } }Notes:
tstlblock contains TSTL‑specific optionsmoduleortargetas TSTL ignores those🖥️ 2. Client Config -
tsconfig.client.jsonClient build extending the base config.
{ "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "./dist/client" }, "include": [ "src/client/**/*", "src/shared/**/*" ], "tstl": { "luaTarget": "5.4" } }🖧 3. Server Config -
tsconfig.server.jsonServer build extending the base config.
{ "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "./dist/server" }, "include": [ "src/server/**/*", "src/shared/**/*" ], "tstl": { "luaTarget": "5.4" } }🧪 Example Source Files
src/shared/utils.tssrc/client/main.tssrc/server/main.ts📦 package.json Example
{ "name": "multi-config-tstl-example", "private": true, "scripts": { "build:client": "npx tstl -p tsconfig.client.json", "build:server": "npx tstl -p tsconfig.server.json", "build": "npm run build:client && npm run build:server" }, "devDependencies": { "typescript-to-lua": "^1.33.2", "typescript": "^5.9.3" } }🏁 Running the Build
Produces:
Freed-Wu commentedon Jan 31, 2026
Cheatoid commentedon Jan 31, 2026
That's actually normal, there is no
fsbinding in tstl. You need to make/use declarations for your Lua environment.Freed-Wu commentedon Jan 31, 2026
@types/nodeandlua-typesconflict, due to repeated definition likerequire.@types/nodeis OK for tsc, However, we need*.d.tsforfs. Even if we add@types/node, it doesn't have any lua source, which will result inerror TSTL: Could not resolve lua source files for require path 'fs' in file index.ts.Zamiell commentedon Jan 31, 2026
Yeah, that's a big problem. Sounds like you are running up against some fundamental technical limitations, as TypeScript isn't meant to be used this way. I think you would have to make your own types library called "lua-and-node-types" that combined exactly what you needed from both types libraries.