mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 01:23: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
|
||||
const source = netscriptDefinitions.replace(/export /g, "");
|
||||
for (const languageDefaults of [
|
||||
monaco.languages.typescript.javascriptDefaults,
|
||||
monaco.languages.typescript.typescriptDefaults,
|
||||
]) {
|
||||
for (const [language, languageDefaults] of [
|
||||
["javascript", monaco.languages.typescript.javascriptDefaults],
|
||||
["typescript", monaco.languages.typescript.typescriptDefaults],
|
||||
] as const) {
|
||||
languageDefaults.addExtraLib(source, "netscript.d.ts");
|
||||
languageDefaults.addExtraLib(reactTypes, "react.d.ts");
|
||||
languageDefaults.addExtraLib(reactDomTypes, "react-dom.d.ts");
|
||||
languageDefaults.setCompilerOptions({
|
||||
...languageDefaults.getCompilerOptions(),
|
||||
// We allow direct importing of `.ts`/`.tsx` files, so tell the typescript language server that.
|
||||
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,
|
||||
// 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({
|
||||
...languageDefaults.getDiagnosticsOptions(),
|
||||
// Show semantic errors, even in javascript.
|
||||
// Note that this will only happen if checking is enabled in javascript (e.g. by `// @ts-check`)
|
||||
noSemanticValidation: false,
|
||||
// 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.typescript.typescriptDefaults.setCompilerOptions({
|
||||
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
|
||||
jsx: monaco.languages.typescript.JsxEmit.ReactJSX,
|
||||
allowUmdGlobalAccess: true,
|
||||
});
|
||||
/**
|
||||
* Ignore these errors in the editor:
|
||||
* - Cannot find module ''. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?(2792)
|
||||
*/
|
||||
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
||||
diagnosticCodesToIgnore: [2792],
|
||||
});
|
||||
|
||||
monaco.languages.json.jsonDefaults.setModeConfiguration({
|
||||
...monaco.languages.json.jsonDefaults.modeConfiguration,
|
||||
//completion should be disabled because the
|
||||
|
Loading…
Reference in New Issue
Block a user