mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 23:38:35 +02:00
EDITOR: Provide type definitions for React and ReactDOM in in-game editor. (#1458)
* Fix the type declaration of `!!raw-loader!` modules. Instead of declaring them to export an object with a single key `default` which is a string, the modules have a default export, which is a string. Note, that this doesn't actually change the generated code, just the types that typescript sees. The code worked before because the only thing done to the values was to coerce the values to a string, which turned into a no-op. * Switch from using `raw-loader` to using a source asset module. `raw-loader` was deprecated in webpack v5.
This commit is contained in:
@@ -3,7 +3,12 @@ import type { ContentFilePath } from "../Paths/ContentFile";
|
||||
import { EventEmitter } from "../utils/EventEmitter";
|
||||
import * as monaco from "monaco-editor";
|
||||
import { loadThemes, makeTheme, sanitizeTheme } from "./ui/themes";
|
||||
import libSource from "!!raw-loader!./NetscriptDefinitions.d.ts";
|
||||
import netscriptDefinitions from "./NetscriptDefinitions.d.ts?raw";
|
||||
// We use a relative paths here to
|
||||
// - bypass the exports in @types/react's package.json
|
||||
// - to prevent typescript from complaining about importing a delcaration file.
|
||||
import reactTypes from "../../node_modules/@types/react/index.d.ts?raw";
|
||||
import reactDomTypes from "../../node_modules/@types/react-dom/index.d.ts?raw";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import { NetscriptExtra } from "../NetscriptFunctions/Extra";
|
||||
import * as enums from "../Enums";
|
||||
@@ -57,9 +62,15 @@ export class ScriptEditor {
|
||||
})();
|
||||
|
||||
// Add ts definitions for API
|
||||
const source = (libSource + "").replace(/export /g, "");
|
||||
monaco.languages.typescript.javascriptDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
monaco.languages.typescript.typescriptDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
const source = netscriptDefinitions.replace(/export /g, "");
|
||||
for (const languageDefaults of [
|
||||
monaco.languages.typescript.javascriptDefaults,
|
||||
monaco.languages.typescript.typescriptDefaults,
|
||||
]) {
|
||||
languageDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
languageDefaults.addExtraLib(reactTypes, "react.d.ts");
|
||||
languageDefaults.addExtraLib(reactDomTypes, "react-dom.d.ts");
|
||||
}
|
||||
monaco.languages.json.jsonDefaults.setModeConfiguration({
|
||||
...monaco.languages.json.jsonDefaults.modeConfiguration,
|
||||
//completion should be disabled because the
|
||||
|
||||
Reference in New Issue
Block a user