mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
EDITOR: Enable strict typechecking of typescript. (#1493)
* EDITOR: Tweak typescript language server configuration to match use. - We allow importing files with `.ts`/`.tsx` extensions. - We use an file-at-a-time transpiler, so we don't support features that require understanding the full type system. - We use the classic `React.createElement` transform.
This commit is contained in:
parent
854c1a5921
commit
02538d6953
@ -63,26 +63,45 @@ export class ScriptEditor {
|
|||||||
|
|
||||||
// Add ts definitions for API
|
// Add ts definitions for API
|
||||||
const source = netscriptDefinitions.replace(/export /g, "");
|
const source = netscriptDefinitions.replace(/export /g, "");
|
||||||
for (const languageDefaults of [
|
for (const [language, languageDefaults] of [
|
||||||
monaco.languages.typescript.javascriptDefaults,
|
["javascript", monaco.languages.typescript.javascriptDefaults],
|
||||||
monaco.languages.typescript.typescriptDefaults,
|
["typescript", monaco.languages.typescript.typescriptDefaults],
|
||||||
]) {
|
] as const) {
|
||||||
languageDefaults.addExtraLib(source, "netscript.d.ts");
|
languageDefaults.addExtraLib(source, "netscript.d.ts");
|
||||||
languageDefaults.addExtraLib(reactTypes, "react.d.ts");
|
languageDefaults.addExtraLib(reactTypes, "react.d.ts");
|
||||||
languageDefaults.addExtraLib(reactDomTypes, "react-dom.d.ts");
|
languageDefaults.addExtraLib(reactDomTypes, "react-dom.d.ts");
|
||||||
}
|
languageDefaults.setCompilerOptions({
|
||||||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
|
...languageDefaults.getCompilerOptions(),
|
||||||
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
|
// We allow direct importing of `.ts`/`.tsx` files, so tell the typescript language server that.
|
||||||
jsx: monaco.languages.typescript.JsxEmit.ReactJSX,
|
allowImportingTsExtensions: true,
|
||||||
|
// We use file-at-a-time transpiler. See https://www.typescriptlang.org/tsconfig/#isolatedModules
|
||||||
|
isolatedModules: true,
|
||||||
|
// We use the classic (i.e. `React.createElement`:) react runtime.
|
||||||
|
jsx: monaco.languages.typescript.JsxEmit.React,
|
||||||
|
// We define `React` and `ReactDOM` as globals. Don't mark using them as errors.
|
||||||
allowUmdGlobalAccess: true,
|
allowUmdGlobalAccess: true,
|
||||||
|
// Enable strict typechecking.
|
||||||
|
// Note that checking in javascript is disabled by default but can be enabled via `// @ts-check`.
|
||||||
|
// This enables strictNullChecks, which impacts reported types, even in javascript.
|
||||||
|
strict: true,
|
||||||
|
noImplicitAny: language === "typescript",
|
||||||
|
noImplicitReturns: true,
|
||||||
});
|
});
|
||||||
/**
|
languageDefaults.setDiagnosticsOptions({
|
||||||
* Ignore these errors in the editor:
|
...languageDefaults.getDiagnosticsOptions(),
|
||||||
* - Cannot find module ''. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?(2792)
|
// Show semantic errors, even in javascript.
|
||||||
*/
|
// Note that this will only happen if checking is enabled in javascript (e.g. by `// @ts-check`)
|
||||||
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
noSemanticValidation: false,
|
||||||
diagnosticCodesToIgnore: [2792],
|
// Ignore these errors in the editor:
|
||||||
|
diagnosticCodesToIgnore: [
|
||||||
|
// We define `React` and `ReactDOM` as globals. Don't mark using them as errors.
|
||||||
|
// Even though we set allowUmdGlobalAccess, it still shows a warning (instead of an error).
|
||||||
|
// - 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.(2686)
|
||||||
|
2686,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
monaco.languages.json.jsonDefaults.setModeConfiguration({
|
monaco.languages.json.jsonDefaults.setModeConfiguration({
|
||||||
...monaco.languages.json.jsonDefaults.modeConfiguration,
|
...monaco.languages.json.jsonDefaults.modeConfiguration,
|
||||||
//completion should be disabled because the
|
//completion should be disabled because the
|
||||||
|
Loading…
Reference in New Issue
Block a user