Skip to content

Commit 56c2111

Browse files
committed
Use new 'isolatedModules' config in tsconfig.json. Update typing.
1 parent efa1aa7 commit 56c2111

File tree

11 files changed

+54
-30
lines changed

11 files changed

+54
-30
lines changed

cli/link/link.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { exists } from "#/utils/fs/exists";
1515
import { getGamePaths } from "#/utils/fs/get_game_paths";
1616
import { isSamePath } from "#/utils/fs/is_same_path";
1717
import { NodeLogger } from "#/utils/logging";
18-
import { Optional } from "#/utils/types";
18+
import { AnyObject, Optional } from "#/utils/types";
1919

2020
const log: NodeLogger = new NodeLogger("LINK");
2121

@@ -36,7 +36,7 @@ export async function linkFolders(parameters: ILinkCommandParameters): Promise<v
3636
await linkGamedataFolders(parameters);
3737
await linkLogsFolders(parameters);
3838
} catch (error) {
39-
log.error("Links creation failed:", red(error.message));
39+
log.error("Links creation failed:", red((error as AnyObject).message));
4040
log.error("Verify steam game installation path or provide fallback in:", CLI_CONFIG);
4141
}
4242
}
@@ -64,7 +64,7 @@ async function linkGamedataFolders(parameters: ILinkCommandParameters): Promise<
6464

6565
await fsp.rm(gameGamedataFolderPath, { recursive: true });
6666
} else {
67-
if (isLink && isSamePath(linkPath, TARGET_GAME_DATA_DIR)) {
67+
if (isLink && isSamePath(linkPath as string, TARGET_GAME_DATA_DIR)) {
6868
log.warn(SKIP_SIGN, "Skip, gamedata link already exists:", blue(gameGamedataFolderPath));
6969
} else if (isLink) {
7070
log.warn(WARNING_SIGN, "Skip, gamedata link already exists but points to another place:", red(linkPath));

cli/link/relink.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CLI_CONFIG } from "#/globals";
44
import { linkFolders } from "#/link/link";
55
import { unlinkFolders } from "#/link/unlink";
66
import { NodeLogger } from "#/utils/logging";
7+
import { AnyObject } from "#/utils/types";
78

89
const log: NodeLogger = new NodeLogger("RELINK");
910

@@ -25,7 +26,7 @@ export async function relinkFolders(parameters: IRelinkCommandParameters): Promi
2526

2627
log.info("Relinked game folders");
2728
} catch (error) {
28-
log.error("Links creation failed:", red(error.message));
29+
log.error("Links creation failed:", red((error as AnyObject).message));
2930
log.error("Verify steam game installation path or provide fallback in:", CLI_CONFIG);
3031
}
3132
}

cli/link/unlink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PLUS_SIGN, SKIP_SIGN, WARNING_SIGN } from "#/globals";
66
import { TARGET_GAME_LINK_DIR, TARGET_LOGS_LINK_DIR } from "#/globals/paths";
77
import { getGamePaths } from "#/utils/fs/get_game_paths";
88
import { NodeLogger } from "#/utils/logging";
9-
import { Optional } from "#/utils/types";
9+
import { AnyObject, Optional } from "#/utils/types";
1010

1111
const log: NodeLogger = new NodeLogger("UNLINK");
1212

@@ -23,7 +23,7 @@ export async function unlinkFolders(): Promise<void> {
2323
await unlink(TARGET_LOGS_LINK_DIR);
2424
await unlink(TARGET_GAME_LINK_DIR);
2525
} catch (error) {
26-
log.error("Links removal failed:", red(error.message));
26+
log.error("Links removal failed:", red((error as AnyObject)?.message));
2727
}
2828
}
2929

cli/parse/utils/get_extern_docs.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from "typescript";
2929

3030
import { IExternCallbackParameterDescriptor, IExternFileDescriptor } from "#/parse/utils/types";
31-
import { Optional } from "#/utils/types";
31+
import { AnyObject, Optional } from "#/utils/types";
3232

3333
/**
3434
* Method name used for externals declaration.
@@ -46,7 +46,7 @@ export function getExternDocs(files: Array<string>): Array<IExternFileDescriptor
4646
.filter((it: Statement) => {
4747
if (!isExpressionStatement(it)) {
4848
return false;
49-
} else if (it.expression?.["expression"]?.escapedText !== EXTERN_METHOD_NAME) {
49+
} else if ((it.expression as AnyObject)?.["expression"]?.escapedText !== EXTERN_METHOD_NAME) {
5050
return false;
5151
}
5252

@@ -64,10 +64,10 @@ export function getExternDocs(files: Array<string>): Array<IExternFileDescriptor
6464
})
6565
.map((statement: Statement) => {
6666
const callExpression: CallExpression = (statement as ExpressionStatement).expression as CallExpression;
67-
const doc: Optional<JSDoc> = statement["jsDoc"] && statement["jsDoc"][0];
67+
const doc: Optional<JSDoc> = (statement as AnyObject)["jsDoc"] && (statement as AnyObject)["jsDoc"][0];
6868
const externCallback: ArrowFunction = callExpression.arguments[1] as ArrowFunction;
6969

70-
const externName: string = callExpression.arguments[0]["text"];
70+
const externName: string = (callExpression.arguments[0] as AnyObject)["text"];
7171
let docComment: string = doc ? (doc.comment as string) : "";
7272
let callbackDescription: Array<IExternCallbackParameterDescriptor> = [];
7373

@@ -77,7 +77,9 @@ export function getExternDocs(files: Array<string>): Array<IExternFileDescriptor
7777
doc.tags
7878
.map((it: JSDocTag): string => {
7979
const tagName: string = it.tagName.escapedText as string;
80-
const itemName = it["name"] ? it["name"].escapedText : null;
80+
const itemName: Optional<string> = (it as AnyObject)["name"]
81+
? (it as AnyObject)["name"].escapedText
82+
: null;
8183

8284
return `[${tagName}] ${itemName ? itemName + " " : ""}${(it.comment as string) || ""}`;
8385
})
@@ -151,28 +153,28 @@ function getNodeTypeLabel(node: TypeNode | NullLiteral): string {
151153
* Get parameter label for provided AST node.
152154
*/
153155
function getNodeName(node: NamedDeclaration): string {
154-
if ((node.name.kind as SyntaxKind) === SyntaxKind.ArrayBindingPattern) {
156+
if ((node.name?.kind as SyntaxKind) === SyntaxKind.ArrayBindingPattern) {
155157
return `[${(node.name as unknown as ArrayBindingPattern).elements
156158
.map((it) => getNodeName(it as unknown as ParameterDeclaration))
157159
.join(", ")}]`;
158160
} else {
159-
return node.name["escapedText"] as string;
161+
return (node.name as AnyObject)?.["escapedText"] as string;
160162
}
161163
}
162164

163165
/**
164166
* Get descriptor of callback parameter AST node.
165167
*/
166168
function getCallbackParameterDescriptor(parameter: ParameterDeclaration): IExternCallbackParameterDescriptor {
167-
switch (parameter.type.kind) {
169+
switch (parameter.type?.kind) {
168170
case SyntaxKind.NumberKeyword:
169171
case SyntaxKind.StringKeyword:
170172
case SyntaxKind.BooleanKeyword:
171173
case SyntaxKind.NullKeyword:
172174
case SyntaxKind.TupleType:
173175
return {
174176
parameterName: getNodeName(parameter),
175-
parameterTypeName: getNodeTypeLabel(parameter.type),
177+
parameterTypeName: getNodeTypeLabel(parameter.type as TypeNode),
176178
};
177179

178180
default:

cli/test/jest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module.exports = {
2626
"ts-jest",
2727
{
2828
tsconfig: path.resolve(ROOT_DIR, "src/tsconfig.json"),
29-
isolatedModules: true,
3029
},
3130
],
3231
},

cli/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"target": "esnext",
77
"module": "commonjs",
88
"moduleResolution": "node",
9+
"isolatedModules": true,
910
"rootDir": "../",
1011
"baseUrl": "./",
1112
"jsx": "react",

cli/utils/fs/get_game_paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function getGamePaths(): Promise<TGamePaths> {
3838
const normalPath: string = path.normalize(location);
3939
const isAbsolute: boolean = path.isAbsolute(normalPath);
4040

41-
paths[name] = isAbsolute ? normalPath : path.join(gamePath, normalPath);
41+
paths[name as keyof TGamePaths] = isAbsolute ? normalPath : path.join(gamePath, normalPath);
4242

4343
return paths;
4444
}, {} as TGamePaths);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as path from "path";
22

33
/**
4-
* Get parent folder from provided path.
4+
* @param directory - target directory to get parent
5+
* @returns parent folder from provided path
56
*/
67
export function getPathParentFolder(directory: string): string {
78
// Normalize win32 base to omit disk name from path root.
89
if (/^[A-Z]:\\.+/.test(directory)) {
910
directory = directory.slice(2);
1011
}
1112

12-
return path.dirname(directory.replaceAll(path.win32.sep, path.posix.sep)).split(path.posix.sep).pop();
13+
return path.dirname(directory.replaceAll(path.win32.sep, path.posix.sep)).split(path.posix.sep).pop() as string;
1314
}

cli/utils/ltx/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ export interface ILtxFieldDescriptor<T> {
4343
export interface ILtxConfigDescriptor
4444
extends Record<
4545
string,
46-
ILtxConfigDescriptor | Record<string, ILtxFieldDescriptor<unknown> | TPrimitive> | TPrimitive
46+
| ILtxConfigDescriptor
47+
| Record<string, ILtxFieldDescriptor<unknown> | TPrimitive | null | undefined>
48+
| TPrimitive
49+
| null
50+
| undefined
4751
> {
48-
[index: symbol]: Record<string, ILtxFieldDescriptor<unknown> | TPrimitive> | TPrimitive;
52+
[index: symbol]:
53+
| Record<string, ILtxFieldDescriptor<unknown> | TPrimitive | null | undefined>
54+
| TPrimitive
55+
| null
56+
| undefined;
4957
}
5058

5159
/**
@@ -69,5 +77,5 @@ export const LTX_INCLUDE: unique symbol = Symbol("LTX_INCLUDE");
6977
export interface IConditionListDescriptor {
7078
condition?: Array<string>;
7179
action?: Array<string>;
72-
value?: string | number | boolean;
80+
value?: Optional<string | number | boolean>;
7381
}

src/engine/core/managers/interface/LoadScreenManager.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ describe("LoadScreenManager", () => {
1212
it("should correctly generate tips for single player", () => {
1313
const loadScreenManager: LoadScreenManager = getManager(LoadScreenManager);
1414

15-
expect(typeof loadScreenManager.getRandomTipIndex("test")).toBe("number");
16-
expect(typeof loadScreenManager.getRandomTipIndex("test")).toBe("number");
17-
expect(loadScreenManager.getRandomTipIndex("test")).toBeGreaterThanOrEqual(0);
18-
expect(loadScreenManager.getRandomTipIndex("test")).toBeGreaterThanOrEqual(0);
15+
expect(typeof loadScreenManager.getRandomTipIndex()).toBe("number");
16+
expect(typeof loadScreenManager.getRandomTipIndex()).toBe("number");
17+
expect(loadScreenManager.getRandomTipIndex()).toBeGreaterThanOrEqual(0);
18+
expect(loadScreenManager.getRandomTipIndex()).toBeGreaterThanOrEqual(0);
1919
});
2020

2121
it("should correctly generate tips for multiplayer", () => {
2222
const loadScreenManager: LoadScreenManager = getManager(LoadScreenManager);
2323

24-
expect(typeof loadScreenManager.getRandomMultiplayerTipIndex("test")).toBe("number");
25-
expect(typeof loadScreenManager.getRandomMultiplayerTipIndex("test")).toBe("number");
26-
expect(loadScreenManager.getRandomMultiplayerTipIndex("test")).toBeGreaterThanOrEqual(0);
27-
expect(loadScreenManager.getRandomMultiplayerTipIndex("test")).toBeGreaterThanOrEqual(0);
24+
expect(typeof loadScreenManager.getRandomMultiplayerTipIndex()).toBe("number");
25+
expect(typeof loadScreenManager.getRandomMultiplayerTipIndex()).toBe("number");
26+
expect(loadScreenManager.getRandomMultiplayerTipIndex()).toBeGreaterThanOrEqual(0);
27+
expect(loadScreenManager.getRandomMultiplayerTipIndex()).toBeGreaterThanOrEqual(0);
2828
});
2929
});

0 commit comments

Comments
 (0)