Skip to content

Commit fb6c01c

Browse files
committed
Address review: null-safe splitTextLines spread, typed hook test cases
Replace the @ts-ignore-only approach with a real null guard (splitTextLines(text) ?? []) in TextLinesMutator.insert, and replace the any[] cast in hooks.ts with an explicit HookFnTestCase type so the concatenated test cases stay shape-checked.
1 parent a3ae764 commit fb6c01c

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/static/js/TextLinesMutator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class TextLinesMutator {
280280
if (!this._inSplice) this._enterSplice();
281281
if (L) {
282282
// @ts-ignore
283-
const newLines = splitTextLines(text);
283+
const newLines = splitTextLines(text) ?? [];
284284
if (this._isCurLineInSplice()) {
285285
const sline = this._curSplice.length - 1;
286286
/** @type {string} */

src/tests/backend/specs/hooks.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ describe(__filename, function () {
6565
});
6666

6767
// Hook functions that should work for both synchronous and asynchronous hooks.
68-
const supportedSyncHookFunctions = [
68+
type HookFnTestCase = {
69+
name: string;
70+
fn: (hn: any, ctx: any, cb?: any) => any;
71+
want?: unknown;
72+
wantErr?: string;
73+
syncOk?: boolean;
74+
};
75+
const supportedSyncHookFunctions: HookFnTestCase[] = [
6976
{
7077
name: 'return non-Promise value, with callback parameter',
7178
fn: (hn:Function, ctx:any, cb:Function) => 'val',
@@ -563,7 +570,7 @@ describe(__filename, function () {
563570
});
564571

565572
describe('supported hook function styles', function () {
566-
const supportedHookFunctions = (supportedSyncHookFunctions as any[]).concat([
573+
const supportedHookFunctions = supportedSyncHookFunctions.concat([
567574
{
568575
name: 'legacy async cb',
569576
fn: (hn:Function, ctx:any, cb:Function) => { process.nextTick(cb, 'val'); },

0 commit comments

Comments
 (0)