diff --git a/code/lib/instrumenter/src/instrumenter.test.ts b/code/lib/instrumenter/src/instrumenter.test.ts index c15d5516fd1c..da65f5498dd7 100644 --- a/code/lib/instrumenter/src/instrumenter.test.ts +++ b/code/lib/instrumenter/src/instrumenter.test.ts @@ -29,6 +29,7 @@ class HTMLElement { } } +// @ts-expect-error (global scope type conflicts) delete global.location; // @ts-expect-error (global scope type conflicts) global.location = { reload: jest.fn() }; diff --git a/code/lib/instrumenter/src/instrumenter.ts b/code/lib/instrumenter/src/instrumenter.ts index 0d8c2c9ddc78..357b9df52817 100644 --- a/code/lib/instrumenter/src/instrumenter.ts +++ b/code/lib/instrumenter/src/instrumenter.ts @@ -40,8 +40,10 @@ const alreadyCompletedException = new Error( `This function ran after the play function completed. Did you forget to \`await\` it?` ); -const isObject = (o: unknown) => Object.prototype.toString.call(o) === '[object Object]'; -const isModule = (o: unknown) => Object.prototype.toString.call(o) === '[object Module]'; +const isObject = (o: unknown): o is object => + Object.prototype.toString.call(o) === '[object Object]'; +const isModule = (o: unknown): o is NodeModule => + Object.prototype.toString.call(o) === '[object Module]'; const isInstrumentable = (o: unknown) => { if (!isObject(o) && !isModule(o)) return false; if (o.constructor === undefined) return true; @@ -108,7 +110,7 @@ export class Instrumenter { isPlaying = true, isDebugging = false, }: { - storyId?: StoryId; + storyId: StoryId; isPlaying?: boolean; isDebugging?: boolean; }) => { @@ -575,8 +577,8 @@ export class Instrumenter { return; } - const hasPrevious = logItems.some((item) => - [CallStates.DONE, CallStates.ERROR].includes(item.status) + const hasPrevious = logItems.some( + (item) => item.status === CallStates.DONE || item.status === CallStates.ERROR ); const controlStates: ControlStates = { start: hasPrevious, diff --git a/code/lib/instrumenter/src/types.ts b/code/lib/instrumenter/src/types.ts index 4d8097b91cb0..1076d4dd3a1d 100644 --- a/code/lib/instrumenter/src/types.ts +++ b/code/lib/instrumenter/src/types.ts @@ -61,7 +61,14 @@ export interface SyncPayload { } export interface State { - renderPhase: 'loading' | 'rendering' | 'playing' | 'played' | 'completed' | 'aborted' | 'errored'; + renderPhase?: + | 'loading' + | 'rendering' + | 'playing' + | 'played' + | 'completed' + | 'aborted' + | 'errored'; isDebugging: boolean; isPlaying: boolean; isLocked: boolean; @@ -73,7 +80,7 @@ export interface State { ancestors: Call['id'][]; playUntil?: Call['id']; resolvers: Record; - syncTimeout: ReturnType; + syncTimeout?: ReturnType; forwardedException?: Error; } diff --git a/code/lib/instrumenter/tsconfig.json b/code/lib/instrumenter/tsconfig.json index 4c6f20a1be4d..b5a2f9a70918 100644 --- a/code/lib/instrumenter/tsconfig.json +++ b/code/lib/instrumenter/tsconfig.json @@ -2,6 +2,6 @@ "extends": "../../tsconfig.json", "include": ["src/**/*"], "compilerOptions": { - "strict": false + "strict": true } }