I am trying to build typescript typings for a mod for Minecraft that runs an embedded…
- User
I am trying to build typescript typings for a mod for Minecraft that runs an embedded version of JavaScript (via Mozilla Rhino). The mod uses 3 folders to load scripts depending on the environment (
server_scripts,client_scripts, andstartup_scripts). The mod creates a folder structure like this:codekubejs ├── client_scripts/ │ ├── script1.js │ └── script2.js ├── server_scripts/ │ ├── script1.js │ └── script2.js ├── startup_scripts/ │ ├── script1.js │ └── script2.jsEach of these environment folders should have a different set of typings since the mod exposes different types based on the environment (in the global scope) and the mod uses namespaces, not modules, so I cant simply rely on modules to only import the correct types. Also, there are some shared types which I put in the
@kubejs/corefolder which needs to be accessible by@kubejs/client,@kubejs/server, and@kubejs/startup. I want to keep the typings out of the scripts folders because eventually I plan on putting them in their own repo so I have my project structured like this so far:codekubejs/ ├── @types/ │ └── @kubejs/ │ ├── core/ │ │ ├── index.d.ts │ │ └── tsconfig.json (extends `tsconfig.base.json`) │ ├── client/ │ │ ├── index.d.ts │ │ └── tsconfig.json (extends `tsconfig.base.json`, references `@kubejs/core`) │ ├── server/ │ │ ├── index.d.ts │ │ └── tsconfig.json (extends `tsconfig.base.json`, references `@kubejs/core`) │ └── startup/ │ ├── index.d.ts │ └── tsconfig.json (extends `tsconfig.base.json`, references `@kubejs/core`) ├── client_scripts/ │ ├── script1.js │ └── script2.js ├── server_scripts/ │ ├── script1.js │ └── script2.js ├── startup_scripts/ │ ├── script1.js │ └── script2.js ├── tsconfig.json └── tsconfig.base.jsonHowever I cant seem to figure out how to get to see the types in . I have tried to adding and / to the but I cant seem to get it working.
- Assistant
To make
@kubejs/startupsee the types in@kubejs/core, you can use thetypeRootsoption in thetsconfig.jsonfile. Here's an example of how you can modify thetsconfig.jsonfile for@kubejs/startup:json{ "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "./dist", "rootDir": "./src", "moduleResolution": "node", "target": "es5", "lib": ["es5", "es6", "dom"], "types": ["@kubejs/core"], "typeRoots": ["./node_modules/@types", "./@kubejs/core"] }, "include": ["./src/**/*"], "exclude": ["./node_modules", "./dist"] }In this configuration, the
typesoption is set to@kubejs/core, which tells TypeScript to include the types from that package. ThetypeRootsoption is set to include both thenode_modules/@typesdirectory and the@kubejs/coredirectory. This allows TypeScript to search for types in both locations.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.